刚入手一手房怎么网上做网站,德宏网站制作,百度联盟怎么加入赚钱,wordpress迷关键在于动态获取滚动坐标值 测试滚动事件 $(window).scroll(function(){ console.log($(window).scrolltop()); }) 获取三个高度#xff1a;窗口高度#xff0c;盒子高度以及滚动坐标值#xff0c;将广告盒子设置为绝对定位#xff0c;当鼠标滚动时#xff0c;其top值为滚… 关键在于动态获取滚动坐标值 测试滚动事件 $(window).scroll(function(){ console.log($(window).scrolltop()); }) 获取三个高度窗口高度盒子高度以及滚动坐标值将广告盒子设置为绝对定位当鼠标滚动时其top值为滚动坐标值窗口高度/2-盒子高度/2 css代码 stylediv{width:50px;height:200px;position: absolute;top:0;background: lightgreen;}.right{right:0;}/style JQ代码 1 script2 $(function(){3 //获得三个高度4 5 var h2 $(window).height();//窗口高度6 var h3 $(div).height();//盒子高度7 //滚动事件8 $(window).scroll(function(){9 var h1 $(window).scrollTop();//滚动值
10 $(div).stop().animate({top:h1h2/2-h3/2},200); //注意加动画前加stop()
11 })
12 $(span).on(click,function(){
13 $(this).parent().css(display,none);
14 })
15
16 })
17 /script 转载于:https://www.cnblogs.com/shisanjun/p/4814154.html