jQuery實(shí)現(xiàn)滑動(dòng)頁(yè)面固定頂部顯示(可根據(jù)顯示位置消失與替換)
本文實(shí)例講述了jQuery實(shí)現(xiàn)滑動(dòng)頁(yè)面固定頂部顯示(可根據(jù)顯示位置消失與替換)。分享給大家供大家參考,具體如下:
這里介紹的jQuery拉動(dòng)頁(yè)面固定頂部顯示,及自動(dòng)消失效果,可能ie瀏覽器下有問(wèn)題,不過(guò)火狐什么的都可以運(yùn)行看效果,一個(gè)簡(jiǎn)單的網(wǎng)頁(yè)特效,也是很常用的“回到頂部”效果,有興趣的看一下。
運(yùn)行效果截圖如下:
在線演示地址如下:
http://demo.jb51.net/js/2015/jquery-fix-top-cha-show-codes/
具體代碼如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>回到頂部:哭泣的小丑</title> <script src="jquery-1.6.2.min.js"></script> <!-- CSS模板清除 --> <style> html, body, div, span, applet, object, iframe,h1, h2, h3, h4, h5, h6, p, blockquote, pre,a, abbr, acronym, address, big, cite, code,del, dfn, em, img, ins, kbd, q, s, samp,small, strike, strong, sub, sup, tt, var,b, u, i, center,dl, dt, dd, ol, ul, li,fieldset, form, label, legend, input,table, caption, tbody, tfoot, thead, tr, th, td,article, aside, canvas, details, embed,figure, figcaption, footer, header, hgroup,menu, nav, output, ruby, section, summary,time, mark, audio, video {margin: 0;padding: 0;border: 0;font-size: 100%;} article, aside, details, figcaption, figure,footer, header, hgroup, menu, nav, section {display: block;float:left;}select, input, button,button img, label {vertical-align: middle;}body {font:normal 12px/1.5 "Microsoft Yahei","微軟雅黑",Tahoma,Arial,Helvetica,STHeiti; webkit-font-smoothing:antialiased;-moz-font-smoothing: subpixel-antialiased; color:#666;}ol, ul {list-style: none;}blockquote, q {quotes: none;}blockquote:before, blockquote:after,q:before, q:after {content: '';content: none;}table {border-collapse: collapse;border-spacing: 0;}em {font-style: normal}select, input, button, button img, label {vertical-align:middle;}input {font-family:"Microsoft Yahei","微軟雅黑";webkit-font-smoothing:antialiased;-moz-font-smoothing: subpixel-antialiased}input, input:focus, button, button:focus, select,textarea, textarea:focus {outline:none; -moz-outline:none; -webkit-outline:none; }input:focus { outline:none; -moz-outline:none; -webkit-outline:none; }textarea {resize:none;}a {color:#666; text-decoration:none;} a:hover {text-decoration:underline;}a:focus {outline:none; -moz-outline:none;-webkit-outline:none;}body {min-width: 960px;} </style> <!-- CSS模板清除 E--> <!-- main CSS --> <style> body{background:#e7e7e7;} .clearfix:before, .clearfix:after, .container_24:before, .container_24:after { content: '.'; display: block; overflow: hidden; visibility: hidden; font-size: 0; line-height: 0; width: 0; height: 0;} .clearfix:after, .container_24:after { clear: both; } .Xc_main{width:750px;margin:0 auto;position:relative;} .Xc_left{float:left;} .Xc_left h1{font-size:24px;padding-top:25px;} .Xc_right{float:right;width:600px;} .Xc_right .Xc_list{margin:10px 0 10px 0;} .Xc_list_top,.Xc_list_main{background:#fff;padding:10px;border:1px solid #ccc;} .Xc_list_top{margin-bottom:10px;} .Xc_gg{width:90px;height:90px;border:1px solid #ccc;background:#fff;text-align:center;} .Xc_bottom{height:650px;background:#fff;padding:10px;border:1px solid #ccc;position:relative;} </style> <!-- main CSS E--> </head> <script> $(function () { $(".Xc_list_top").css("width",$(".Xc_list_main").width()); var resetRightPanelPostion = function () { var msie6 = $.browser.msie && $.browser.version == '6.0' && $.browser.version < 7; if ($.browser.safari) { bodyelem = $("body"); } else { bodyelem = $("html,body"); } var bodyTop = bodyelem.scrollTop(); var top = $(".Xc_left").offset().top; //var t = $("#public_footer").offset().top; var t = $("#footerDestinationBox").offset().top; //var bottom = $("#footerDestinationBox").offset().top; for(var i = 0 ; i < $(".Xc_list .Xc_list_top").length ; i++){ if (bodyTop >= top && ((bodyTop + $(".Xc_left").outerHeight()) < t)) { if (!msie6) { if (bodyTop + $(".Xc_gg").outerHeight() >= t) { $(".Xc_gg").removeClass('fixed').css({ "position": "absolute", "top": t - $(".Xc_gg").outerHeight() + "px" }); } else { $(".Xc_gg").css({ "position": "fixed", "top": 0 }); } } } else { if (!msie6) { $(".Xc_gg").css({ "position": "static" }); } } if(bodyTop>$(".Xc_list").eq(i).offset().top){ $(".Xc_list_top").eq(i).css({position:"absolute",top:top-168}); } if(bodyTop>$(".Xc_list").eq(i).offset().top){ $(".Xc_list_top").eq(i).css({position:"fixed",top:0}); } if(bodyTop<=$(".Xc_list").eq(i).offset().top){ $(".Xc_list_top").eq(i).css({position:"static",top:0}); } } }; window.onload = function () { if ($(".Xc_gg").length) { resetRightPanelPostion(); $(window).scroll(function () { resetRightPanelPostion(); }); } } }) </script> <body> <div class="Xc_main clearfix"> <div class="clearfix" style="margin-top:90px;float:left;"> <div class="Xc_left"> <div class="Xc_gg"> <h1>小丑</h1> <div style="margin-top:40px;">Q群:<em style="color:#0069D6;">150508281</em></div> </div> </div> </div> <div class="Xc_right clearfix"> <div class="Xc_list"> <div class="Xc_list_top" id="Xc_list_top">top 1</div> <div class="Xc_list_main" style="height:300px;background:#fff;"> </div> </div> <div class="Xc_list"> <div class="Xc_list_top">top 2</div> <div class="Xc_list_main" style="height:300px;background:#fff;"> </div> </div> <div class="Xc_list"> <div class="Xc_list_top">top 3</div> <div class="Xc_list_main" style="height:300px;background:#fff;"> </div> </div> <div class="Xc_list"> <div class="Xc_list_top">top 4</div> <div class="Xc_list_main" style="height:300px;background:#fff;"> </div> </div> <div class="Xc_list"> <div class="Xc_list_top">top 5</div> <div class="Xc_list_main" style="height:300px;background:#fff;"> </div> </div> <div class="Xc_list"> <div class="Xc_list_top">top 6</div> <div class="Xc_list_main" style="height:300px;background:#fff;"> </div> </div> </div> </div> <div class="Xc_bottom clearfix" id="footerDestinationBox"> <div style="position:absolute;top:40px;right:50px;"> by 藍(lán)色理想 @哭泣的小丑</div> </div> </body> </html>
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery操作dom實(shí)現(xiàn)彈出頁(yè)面遮罩層(web端和移動(dòng)端阻止遮罩層的滑動(dòng))
- jquery實(shí)現(xiàn)網(wǎng)頁(yè)的頁(yè)面平滑滾動(dòng)效果代碼
- JQuery實(shí)現(xiàn)鼠標(biāo)滾輪滑動(dòng)到頁(yè)面節(jié)點(diǎn)
- jQuery的Scrollify插件實(shí)現(xiàn)滑動(dòng)到頁(yè)面下一節(jié)點(diǎn)
- JQuery 實(shí)現(xiàn)在同一頁(yè)面錨點(diǎn)鏈接之間的平滑滾動(dòng)
- jQuery創(chuàng)建平滑的頁(yè)面滾動(dòng)(頂部或底部)
- 基于jquery的從一個(gè)頁(yè)面跳轉(zhuǎn)到另一個(gè)頁(yè)面的指定位置的實(shí)現(xiàn)代碼(帶平滑移動(dòng)的效果)
- jQuery實(shí)現(xiàn)彈窗下底部頁(yè)面禁止滑動(dòng)效果
相關(guān)文章
jQuery UI Draggable + Sortable 結(jié)合使用(實(shí)例講解)
下面小編就為大家?guī)?lái)一篇jQuery UI Draggable + Sortable 結(jié)合使用(實(shí)例講解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09jQuery實(shí)現(xiàn)嵌套選項(xiàng)卡功能
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)嵌套選項(xiàng)卡功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-0820個(gè)最常見(jiàn)的jQuery面試問(wèn)題及答案
本篇文章給大家分享了20個(gè)最常見(jiàn)的jQuery面試問(wèn)題及答案,對(duì)此有需要的朋友可以參考下。2018-05-05Jquery幻燈片特效代碼分享 打開(kāi)頁(yè)面隨機(jī)選擇切換方式(3)
jQuery是一個(gè)非常優(yōu)秀的 JavaScript 框架,使用簡(jiǎn)單靈活,一個(gè)漂亮的幻燈片更能吸引訪客的注意力。本文實(shí)例講述了jQuery實(shí)現(xiàn)時(shí)尚漂亮的幻燈片特效,基本能滿足你在網(wǎng)頁(yè)上使用幻燈片(焦點(diǎn)圖)效果。分享給大家供大家參考。具體如下:2015-08-08jQuery表單驗(yàn)證插件formValidator(改進(jìn)版)
隨著jQuery被越來(lái)越多的人使用,基于jQuery的表單驗(yàn)證插件,也從無(wú)到現(xiàn)在比較流行的已經(jīng)有10個(gè)左右了2012-02-02jquery+css實(shí)現(xiàn)絢麗的橫向二級(jí)下拉菜單-附源碼下載
這篇文章主要介紹了jquery+css實(shí)現(xiàn)絢麗的橫向二級(jí)下拉菜單-附源碼下載,需要的朋友可以參考下2015-08-08Jquery插件easyUi表單驗(yàn)證提交(示例代碼)
本篇文章主要是對(duì)Jquery插件easyUi表單驗(yàn)證提交的示例代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12jQuery中用on綁定事件時(shí)需注意的事項(xiàng)
本篇文章主要介紹了jQuery中用on綁定事件時(shí)需注意的事項(xiàng),具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-03-03jQuery快速上手:寫(xiě)jQuery與直接寫(xiě)JS的區(qū)別詳細(xì)解析
jQuery代碼具體的寫(xiě)法和原生的Javascript寫(xiě)法在執(zhí)行常見(jiàn)操作時(shí)的區(qū)別如下所示。需要的朋友可以過(guò)來(lái)參考下2013-08-08