欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

两侧跟随的广告

程序员文章站 2022-06-23 23:43:26
跟随的广告

跟随的广告

    <style>
        img{
            position: absolute;
            left:0;
            top:50px;
        }
        #demo{
            width:1000px;
            margin:0 auto;
        }
    </style>
</head>
 
<body>
	<img src="images/aside.jpg" alt="" 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>

  两侧跟随的广告