码迷,mamicode.com
首页 > 其他好文 > 详细

两侧跟随的广告

时间:2019-11-25 11:34:10      阅读:52      评论:0      收藏:0      [点我收藏+]

标签:运动   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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!