首页 > Web开发 > 详细

元素随滚动条位置变动而发生位置变化(从固定浏览器位置到固定网页位置)

时间:2015-08-26 07:11:31      阅读:182      评论:0      收藏:0      [点我收藏+]
var clientHeight = $(window).height(); window.onscroll = function(){ var top = document.getElementsByClassName("bottom")[0].getBoundingClientRect().top; console.log(top); if(top < clientHeight){ $("div.go_crash").css("position", "relative");
    }else{ if($("div.go_crash").css("position") == "relative"){ $("div.go_crash").css("position", "fixed");
        }
    }
};


document.getElementsByClassName("bottom")需要做判断的元素


$("div.go_crash") 实际需要变换位置的元素




元素随滚动条位置变动而发生位置变化(从固定浏览器位置到固定网页位置)

原文:http://my.oschina.net/u/232595/blog/497110

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!