手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jQuery实现浮动层随浏览器滚动条滚动的方法
jQuery实现浮动层随浏览器滚动条滚动的方法
摘要:本文实例讲述了jQuery实现浮动层随浏览器滚动条滚动的方法。分享给大家供大家参考。具体如下:这是jQuery实现的一个浮动层效果,随浏览器...

本文实例讲述了jQuery实现浮动层随浏览器滚动条滚动的方法。分享给大家供大家参考。具体如下:

这是jQuery实现的一个浮动层效果,随浏览器滚动条而滚动,并一直保持在顶部位置,请使用火狐测试,IE下表现不尽理想。

运行效果截图如下:

jQuery实现浮动层随浏览器滚动条滚动的方法1

在线演示地址如下:

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> <div>sadfsadfasfsafd</div> <div> <div id="c_left"> 羞涩的浮动层... </div> </div> <div></div> </body> </html>

希望本文所述对大家的jQuery程序设计有所帮助。

【jQuery实现浮动层随浏览器滚动条滚动的方法】相关文章:

JavaScript实现点击自动选择TextArea文本的方法

jQuery实现表格行上下移动和置顶效果

JS实现两表格里数据来回转移的方法

JS实现窗口加载时模拟鼠标移动的方法

JS实现定时自动关闭DIV层提示框的方法

JQuery自动触发事件的方法

jQuery实现首页图片淡入淡出效果的方法

jQuery实现dialog设置focus焦点的方法

jquery实现图片左右切换的方法

js实现鼠标经过表格行变色的方法

精品推荐
分类导航