`
一笑_奈何
  • 浏览: 66827 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

jquery实现随屏滚动

阅读更多
看这篇文章之前,建议大家先看
jQuery---10行代码搞定跟随屏幕滚动的层.
http://www.cssrain.cn/article.asp?id=1177

这个7行代码的,意思也差不多,只不过少了3行代码,嘿嘿。
先看演示:
http://www.cssrain.cn/demo/floatDIV.html

具体代码:
先绝对定位 div 层,
然后脚本控制层的位置:
$(document).ready(function(){
    var menuYloc = $("#test").offset().top;
    $(window).scroll(function (){
        var offsetTop = menuYloc + $(window).scrollTop() +"px";
        $("#test").animate({top : offsetTop },{ duration:600 , queue:false });
    });
});
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics