js實現(xiàn)可控制左右方向的無縫滾動效果
本文實例為大家分享了無縫滾動效果JavaScript代碼實現(xiàn),供大家參考,具體內(nèi)容如下】
效果圖:

實現(xiàn)代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312" />
<title>zzzz</title>
<style>
*{
margin: 0;
padding:0;
}
body{
width: 1000px;
margin: 100px auto;
background-color: #fff;
}
#wrapper{
overflow: hidden;
width: 600px;
height: 100px;
position: relative;
}
#wrapper ul {
position: absolute;
left: 0;
top: 0;
}
#wrapper li{
float: left;
list-style: none;
}
#wrapper li img{
width: 150px;
height: 100px;
border-radius: 9px;
}
input[type=button]{
margin-top: 20px;
width: 35px;
height: 25px;
line-height: 25px;
}
</style>
<script type="text/javascript">
window.onload=function(){
var timer=null;
var speed=4;
var od=document.getElementById("wrapper");
var au=od.getElementsByTagName('ul')[0];
var ali=au.getElementsByTagName('li');
au.innerHTML=au.innerHTML+au.innerHTML;
au.style.width=ali[0].offsetWidth*ali.length+'px';
timer=setInterval(move,30)
function move(){
if(au.offsetLeft<-au.offsetWidth/2){
au.style.left='0';
}
if(au.offsetLeft>0){
au.style.left=-au.offsetWidth/2+'px';
}
au.style.left=au.offsetLeft+speed+'px';
}
od.onmouseover=function(){
clearInterval(timer);
}
od.onmouseout=function(){
timer=setInterval(move,30)
}
document.getElementById("btn1").onclick=function(){
speed=-4;
}
document.getElementById("btn2").onclick=function(){
speed=4;
}
}
</script>
</head>
<body>
<div id="wrapper">
<ul>
<li><img src="img/pic4.jpg"/></li>
<li><img src="img/pic3.jpg"/></li>
<li><img src="img/pic2.jpg"/></li>
<li><img src="img/pic1.jpg"/></li>
</ul>
</div>
<input type="button" name="" id="btn1" value="向左" />
<input type="button" id="btn2" value="向右"/>
</body>
</html>
大家可以參考以下專題進行學(xué)習(xí):
《JavaScript滾動效果匯總》《jQuery滾動效果匯總》 《JavaScript圖片輪播效果匯總》
以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)JavaScript程序設(shè)計有所幫助。
相關(guān)文章
學(xué)習(xí)JavaScript設(shè)計模式之代理模式
這篇文章主要為大家介紹了JavaScript設(shè)計模式中的狀態(tài)模式,對JavaScript設(shè)計模式感興趣的小伙伴們可以參考一下2016-01-01
js實現(xiàn)鼠標(biāo)點擊頁面彈出自定義文字效果
這篇文章主要為大家詳細介紹了js實現(xiàn)鼠標(biāo)點擊頁面彈出自定義文字效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-12-12
基于JavaScript實現(xiàn)類似于百度學(xué)術(shù)高級檢索功能
這篇文章主要介紹了基于JavaScript實現(xiàn)類似于百度學(xué)術(shù)高級檢索功能 的相關(guān)資料,需要的朋友可以參考下2016-03-03
javascript中運用閉包和自執(zhí)行函數(shù)解決大量的全局變量問題
做為一個javascript新手,為了程式的簡便,可能會在javascript中運用了大量的全局變量,雖然一時看來,問題解決了,而且也可能讓編碼變得更加的簡單。2010-12-12
基于Bootstrap漂亮簡潔的CSS3價格表(附源碼下載)
該價格表基于Bootstrap網(wǎng)格系統(tǒng)來進行布局,通過簡單的CSS3代碼來美化價格表,樣式非常的時尚漂亮,且能在不同屏幕下展示良好的效果,需要的朋友可以參考下2017-02-02

