jQuery實現(xiàn)浮動層隨瀏覽器滾動條滾動的方法
本文實例講述了jQuery實現(xiàn)浮動層隨瀏覽器滾動條滾動的方法。分享給大家供大家參考。具體如下:
這是jQuery實現(xiàn)的一個浮動層效果,隨瀏覽器滾動條而滾動,并一直保持在頂部位置,請使用火狐測試,IE下表現(xiàn)不盡理想。
運行效果截圖如下:
在線演示地址如下:
http://demo.jb51.net/js/2015/jquery-float-follow-nav-style-codes/
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery浮動層隨瀏覽器滾動條滾動</title> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> if ($.browser.version != "6.0") { $(window).scroll(function(){ if($(this).scrollTop()>118 &&(($(document).height()-$(this).scrollTop())>($(window).height()+$(".aysw-footer").innerHeight()))){ $("#c_left").css({position: 'fixed', top: '2px'}); }else{ if(($(document).height()-$(this).scrollTop())<=($(window).height()+$(".aysw-footer").innerHeight())){ $("#c_left").css({position: 'absolute', top:($(".aysw-footer").offset().top-$("#c_left").innerHeight()-$(".page-home").offset().top-20) +'px'}); }else{ $("#c_left").css({position: 'absolute', top: '2px'}); } } }); } </script> </head> <body style="height:auto; margin:0; padding:0"> <div style="height:118px;background:#6CF;">sadfsadfasfsafd</div> <div class="page-home" style="min-height:1500px;width:100%; background-color:#FFC; position:relative"> <div id="c_left" style="border:1px solid red; width:200px ;height:800px; color:white;background-color:#333; position:absolute; top:2px"> 羞澀的浮動層... </div> </div> <div class="aysw-footer" style="height:200px; width:100%; background-color:#0C3; position:relative"></div> </body> </html>
希望本文所述對大家的jQuery程序設(shè)計有所幫助。
相關(guān)文章
jQuery實現(xiàn)圖片上傳和裁剪插件Croppie
這篇文章主要介紹了jQuery實現(xiàn)圖片上傳和裁剪插件Croppie,實現(xiàn)最常見的各用戶系統(tǒng)要求用戶上傳和裁剪頭像的應(yīng)用,感興趣的小伙伴們可以參考一下2015-11-11jquery+json實現(xiàn)動態(tài)商品內(nèi)容展示的方法
這篇文章主要介紹了jquery+json實現(xiàn)動態(tài)商品內(nèi)容展示的方法,涉及jQuery操作及解析json格式數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下2016-01-01淺談jQuery中對象遍歷.eq().first().last().slice()方法
本文給大家分析了jQuery中的對象遍歷.eq().first().last().slice()方法的使用,以及他們之間的區(qū)別,jQuery源碼中的使用。2014-11-11利用jQuery的deferred對象實現(xiàn)異步按順序加載JS文件
如果你現(xiàn)在對jQuery中的deferred還不了解,jQuery的deferred對象詳解一文接下來介紹deferred對象如何實現(xiàn)異步順序加載JS文件,感興趣的你可以參考下哈2013-03-03