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
74
75
76
77
78
79
80
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Language" content="zh-cn" />
<title>向左无缝滚动</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
*{
    margin: 0px; padding: 0px; font-size:14px; font-family:‘微软雅黑‘;
}
.clearfix:after{content:‘.‘;display:block;height:0;clear:both;visibility:hidden}
.clearfix{display:inline-block;}
* html .clearfix{height:1%}
.clearfix{display:black;}
ul li{
  list-style:none;
}
#box{
  position:relative; width:520px;height:120px;margin:50px auto; overflow:hidden;
}
#box ul{
  position:absolute; top:0px; left:0px; height:120px;
}
#box ul li{
  width:120px; height:120px; background:green; float:left;display:inline; cursor:pointer;
  font-size:40px; color:#fff; text-align:center; line-height:120px; margin:0 5px;
}
</style>
</head>
<body>
<div id=‘box‘>
    <ul class=‘clearfix‘>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
    </ul>
</div>
<script type="text/javascript">
window.onload = function(){
  var oBox = $(‘box‘);
  var oUl = oBox.getElementsByTagName(‘ul‘)[0];
  var oLi = oUl.getElementsByTagName(‘li‘);
  var timer = null;
  var speed = 2;
  oUl.innerHTML += oUl.innerHTML;
  var oW = parseInt(getStyle(oLi[0],‘width‘))+10;
  oUl.style.width = oW*oLi.length+‘px‘;
  toPlay();
  timer = setInterval(toPlay,30);
  oUl.onmousemove = Move;
  oUl.onmouseout = Out;
  function toPlay(){
    if(oUl.offsetLeft<-oUl.offsetWidth/2){
        oUl.style.left=‘0px‘;
    }
    oUl.style.left = oUl.offsetLeft - speed +‘px‘;
  };
  function Move(){
    clearInterval(timer);
  };
  function Out(){
    timer = setInterval(toPlay,30);
  };
}
function getStyle(obj,attr){
  if(obj.currentStyle){
    return obj.currentStyle[attr];
  }else{
    return getComputedStyle(obj,false)[attr];
  }
};
function $(id){
  return document.getElementById(id);
}
</script> 
</body>
</html>

向右无缝滚动  

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
74
75
76
77
78
79
80
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Language" content="zh-cn" />
<title>向左无缝滚动</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
*{
    margin: 0px; padding: 0px; font-size:14px; font-family:‘微软雅黑‘;
}
.clearfix:after{content:‘.‘;display:block;height:0;clear:both;visibility:hidden}
.clearfix{display:inline-block;}
* html .clearfix{height:1%}
.clearfix{display:black;}
ul li{
  list-style:none;
}
#box{
  position:relative; width:520px;height:120px;margin:50px auto; overflow:hidden;
}
#box ul{
  position:absolute; top:0px; left:0px; height:120px;
}
#box ul li{
  width:120px; height:120px; background:green; float:left;display:inline; cursor:pointer;
  font-size:40px; color:#fff; text-align:center; line-height:120px; margin:0 5px;
}
</style>
</head>
<body>
<div id=‘box‘>
    <ul class=‘clearfix‘>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
    </ul>
</div>
<script type="text/javascript">
window.onload = function(){
  var oBox = $(‘box‘);
  var oUl = oBox.getElementsByTagName(‘ul‘)[0];
  var oLi = oUl.getElementsByTagName(‘li‘);
  var timer = null;
  var speed = 2;
  oUl.innerHTML += oUl.innerHTML;
  var oW = parseInt(getStyle(oLi[0],‘width‘))+10;
  oUl.style.width = oW*oLi.length+‘px‘;
  toPlay();
  timer = setInterval(toPlay,30);
  oUl.onmousemove = Move;
  oUl.onmouseout = Out;
  function toPlay(){
    if(oUl.offsetLeft>0){
        oUl.style.left= -oUl.offsetWidth/2+‘px‘;
    }
    oUl.style.left = oUl.offsetLeft + speed +‘px‘;
  };
  function Move(){
    clearInterval(timer);
  };
  function Out(){
    timer = setInterval(toPlay,30);
  };
}
function getStyle(obj,attr){
  if(obj.currentStyle){
    return obj.currentStyle[attr];
  }else{
    return getComputedStyle(obj,false)[attr];
  }
};
function $(id){
  return document.getElementById(id);
}
</script> 
</body>
</htm

js无缝滚动,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。