無縫滾動js代碼

來源:互聯網
上載者:User

標籤:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>無縫滾動</title>
<style>
* {margin: 0;padding: 0;}
#div1{width: 1600px;height: 300px;background: red; margin:100px auto;overflow: hidden;
position: relative;}
#div1 ul{position: absolute;left:0;}
#div1 ul li{float: left;list-style-type: none;overflow: hidden;left: 0;
top:0;}
input{font-size: 20px;border: 2px solid blue;background-color: aliceblue;margin-left: 800px;}
#div2{width: 1600px;height: 300px;}
</style>
<script>
window.onload=function () {
var oDiv1=document.getElementById(‘div1‘);
var oUl=oDiv1.getElementsByTagName(‘ul‘)[0];
var oLi=oDiv1.getElementsByTagName(‘li‘);
var input1=document.getElementsByTagName(‘input‘)[0];
var input2=document.getElementsByTagName(‘input‘)[1];
var moue=-2;
//在圖片後面再加上一次
oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
oUl.style.width=oLi[0].offsetWidth*oLi.length+‘px‘;
function move() {
if(oUl.offsetLeft<-oUl.offsetWidth/2){
oUl.style.left=‘0‘;
}else if(oUl.offsetLeft>0){
oUl.style.left=-oUl.offsetWidth/2+‘px‘;
}
oUl.style.left=oUl.offsetLeft+moue+‘px‘;
}

var tem=setInterval(move,10)
oDiv1.onmouseover=function () {
clearInterval(tem);
}
oDiv1.onmouseout=function () {
tem=setInterval(move,10)
}
//向左按鈕
input1.onclick=function () {
moue=-6;
}
//向右按鈕
input2.onclick=function () {
moue=6;
}
}
</script>
</head>
<body>
<div id="div1">
<ul>
<li><img src="img/m1.jpg"></li>
<li><img src="img/m2.jpg"></li>
<li><img src="img/m3.jpg"></li>
<li><img src="img/m4.jpg"></li>
<li><img src="img/m5.jpg"></li>
<li><img src="img/m6.jpg"></li>
<li><img src="img/m7.jpg"></li>
<li><img src="img/m8.jpg"></li>
</ul>

</div>
<div id="div2">
<input type="button" value="向左滾動"/>
<input type="button" value="向右滾動"/>
</div>
</body>
</html>

無縫滾動js代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.