jquery实现页面滚动时层智能浮动定位
2013-11-13 15:08
666 查看
css:
js:
参考
http://www.wufangbo.com/jquery-scroll-position-fixed/ http://www.helloweba.com/view-blog-194.html
#wziliao{position: absolute;}
js:
$.fn.smartFloat = function() { var position = function(element) { /*position() 方法返回匹配元素相对于父元素的位置(偏移); 该方法返回的对象包含两个整型属性:top 和 left,以像素计; 此方法只对可见元素有效。 scrollTop() 方法返回或设置匹配元素的滚动条的垂直位置; 该方法对于可见元素和不可见元素均有效。*/ var top = element.position().top, pos = element.css("position"); //console.log(top); $(window).scroll(function() { var scrolls = $(this).scrollTop(); //console.log(scrolls); if (scrolls > top) { if (window.XMLHttpRequest) { //除了IE6外的其他浏览器都支持原生的XHR对象 position: "fixed" element.css({ position: "fixed", top: 0 }); } else { //IE6下不设置,及为样式定义的 position: "absolute" element.css({ top: scrolls }); } } else { element.css({ position: pos, top: top }); } }); }; return $(this).each(function() { position($(this)); }); }; //使用 $(function(){ $("#wziliao").smartFloat(); });
参考
http://www.wufangbo.com/jquery-scroll-position-fixed/ http://www.helloweba.com/view-blog-194.html
相关文章推荐
- js页面滚动浮动层智能定位(jQuery)实现
- jQuery实现页面滚动时层智能浮动定位
- jQuery实现页面滚动时层智能浮动定位
- jQuery实现页面滚动时层智能浮动定位
- 页面滚动时层智能浮动定位,jQuery/MooTools实现
- js页面滚动时层智能浮动定位实现(jQuery)
- js页面滚动时层智能浮动定位实现(jQuery/MooTools)
- jQuery实现页面滚动时层智能浮动定位
- 【代码片段】jQuery实现页面滚动时层智能浮动定位-Fixed Floating Elements
- jQuery实现页面滚动时智能浮动定位
- js页面滚动时层智能浮动定位实现(jQuery/MooTools)
- jQuery实现页面滚动时层智能浮动定位实例探讨
- js页面滚动浮动层智能定位(jQuery)实例页面
- jQuery实现页面滚动时元素智能定位,页面导航栏会自动定位到浏览器顶部
- JQuery页面滚动浮动层智能定位
- jQuery实现页面滚动时元素智能定位
- jQuery实现页面滚动时元素的智能定位