jQuery实现浮动层随浏览器滚动条滚动的方法
作者:bea
本文实例讲述了jQuery实现浮动层随浏览器滚动条滚动的方法。分享给大家供大家参考。具体如下: 这是jQuery实现的一个浮动层效果,随浏览器滚动条而滚动,并一直保持在顶部位置,请使用火狐测试,IE下表现不尽理想。 运行效果截图如下: 在线演示地址如下: http://demo./js/2015/jquery-float-follow-nav-style-codes/ 具体代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
本文实例讲述了jQuery实现浮动层随浏览器滚动条滚动的方法。分享给大家供大家参考。具体如下:
这是jQuery实现的一个浮动层效果,随浏览器滚动条而滚动,并一直保持在顶部位置,请使用火狐测试,IE下表现不尽理想。
运行效果截图如下:
在线演示地址如下:
http://demo./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程序设计有所帮助。
有用 | 无用
这是jQuery实现的一个浮动层效果,随浏览器滚动条而滚动,并一直保持在顶部位置,请使用火狐测试,IE下表现不尽理想。
运行效果截图如下:
在线演示地址如下:
http://demo./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程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- JS基于面向对象实现的拖拽库实例
- JS实现滑动菜单效果代码(包括Tab,选项卡,横向等效果)
- 使用jquery+CSS3实现仿windows10开始菜单的下拉导航菜单特效
- javascript同步服务器时间和同步倒计时小技巧
- js中不同的height, top的区别对比
- JS+CSS实现鼠标滑过时动态翻滚的导航条效果
- avalon js实现仿google plus图片多张拖动排序附源码下载
- JS+CSS实现简易的滑动门效果代码
- JS实现网站菜单拖拽移位效果的方法
- jQuery实现的经典竖向伸缩菜单效果代码
- JS+CSS实现经典的左侧竖向滑动菜单效果
- 直接拿来用的15个jQuery代码片段
- JS实现漂亮的淡蓝色滑动门效果代码
- jQuery Validate验证框架经典大全
- Javascript实现的简单右键菜单类
- js实现无限级树形导航列表效果代码
- JS实现同一个网页布局滑动门和TAB选项卡实例
- JS实现3D图片旋转展示效果代码
- JS+CSS实现带小三角指引的滑动门效果