标签:运动 head mat info class cti onscroll margin stop
跟随的广告
<style> img{ position: absolute; left:0; top:50px; } #demo{ width:1000px; margin:0 auto; } </style> </head> <body> <img src="images/aside.jpg" id="pic"/> <div id="demo"> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> <p>天王盖地虎,小鸡炖蘑菇</p> </div> </body> </html> <script type="text/javascript"> var pic = document.getElementById("pic"); var picT = pic.offsetTop; //50 window.onscroll = function(){ var sTop = document.documentElement.scrollTop || document.body.scrollTop; //img它的top值要运动多少? 目标dis var dis = picT + sTop; move(pic,dis); } var timer = null; function move(obj,target){ clearInterval(timer); timer = setInterval(function(){ var speed = target - obj.offsetTop > 0 ? 5 : -5; if(Math.abs(target - obj.offsetTop) < 5){ obj.style.top = target + "px"; clearInterval(timer); return } obj.style.top = speed + obj.offsetTop + "px"; },20) } </script>
标签:运动 head mat info class cti onscroll margin stop
原文地址:https://www.cnblogs.com/xiaoyaolang/p/11926279.html