js无缝向上滚动代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE HTML>
< html  lang = "en-US" >
< head >
   < meta  charset = "UTF-8" >
   < title >无缝滚动——上下</ title >
   < style  type = "text/css" >
   *{margin:0;padding:0;}
   li{list-style:none;}
   img{border:0;}
   #scroll{width:178px;margin:50px auto;position:relative;}
   .btn{display:block;width:27px;height:27px;margin-left:auto;margin-right:auto;cursor:pointer;}
   .up{background:url(images/up.gif);border:solid 1px red;}
   .down{background:url(images/down.gif);}
   .content{margin:10px 0;height:240px;overflow:hidden;position:relative;border:solid 1px balck;}
   .content ul{position:absolute;top:0;left:0;}
   .content li{height:30px;}
   </ style >
</ head >
< body >
   < div  id = "scroll" >
     < div  class = "content" >
       < ul >
         < li >1</ li >
         < li >1</ li >
         < li >1</ li >
         < li >1</ li >
         < li >1</ li >
         < li >1</ li >
         < li >1</ li >
         < li >1</ li >
       </ ul >
     </ div >
   </ div >
</ body >
</ html >
< script  type = "text/javascript" >
window.onload = function(){
   var oDiv = document.getElementById('scroll');
   var btnUp = document.getElementById('up');
   var btnDown = document.getElementById('down');
   var oUl = oDiv.getElementsByTagName('ul')[0];
   var timer = null;
   var speed = -1;
   oUl.innerHTML += oUl.innerHTML;
   setTimeout(move,1500);
   btnUp.onclick = function(){
     clearInterval(timer);
     speed = -1;
     move();
   };
   btnDown.onclick = function(){
     clearInterval(timer);
     speed = 1;
     move();
   };
   oUl.onmouseover = function(){
     clearInterval(timer);
   };
   oUl.onmouseout = function(){
     move();
   };
   function move(){
     timer = setInterval(function(){
       oUl.style.top = oUl.offsetTop + speed + 'px';
       if(oUl.offsetTop <= - oUl.offsetHeight / 2){
         oUl.style.top = '0';
       }else if(oUl.offsetTop >= 0){
         oUl.style.top = - oUl.offsetHeight / 2 + 'px';
       };
     },30);
   };
};
</ script >


本文转自  小旭依然  51CTO博客,原文链接:http://blog.51cto.com/xuyran/1864804
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值