国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

無縫滾動js代碼通俗易懂(自寫)

2024-05-06 15:46:42
字體:
來源:轉載
供稿:網友
本人閑暇時自寫的無縫滾動js,代碼簡單實用,通俗易懂,曬出來與大家共享,感興趣的朋友可以參考下哈

復制代碼 代碼如下:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文檔</title>
<style>
*{padding:0; margin:0;}
ul{ list-style:none;}
#div{ width:300px; height:100px; margin:100px auto; border:1px solid #ff0000; position:relative; overflow:hidden;}
#div ul{ position:absolute; height:100px; left:0;}
#div ul li{ width:300px; height:100px; line-height:100px; text-align:center; float:left}
</style>
<script>
window.onload=function(){
var oDiv=document.getElementById("div");
var oUl=oDiv.getElementsByTagName("ul")[0];
var oLi=oUl.getElementsByTagName("li");
var oInput=document.getElementsByTagName('input');
oUl.innerHTML +=oUl.innerHTML;
oUl.style.width=oLi[0].offsetWidth*oLi.length+"px";
var iSeep=-2;
var tamer=null;
clearInterval(tamer);
function starMove(){
tamer=setInterval(function(){
oUl.style.left=oUl.offsetLeft+iSeep+"px";
if(-oUl.offsetLeft >= oUl.offsetWidth/2){
oUl.style.left="0px";
}else if(oUl.offsetLeft>0){
oUl.style.left=-oUl.offsetWidth/2+"px";
}
},30)
}
starMove();
oDiv.onmouseover=function(){
clearInterval(tamer);
}
oDiv.onmouseout=function(){
starMove();
}
oInput[0].onclick=function(){
iSeep=-2;
}
oInput[1].onclick=function(){
iSeep=2;
}
}
</script>
</head>
<body>
<input type="button" value="左">
<input type="button" value="右">
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
</body>
</html>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 宜良县| 宜兰市| 内丘县| 阿拉善右旗| 长阳| 新郑市| 英吉沙县| 茌平县| 垣曲县| 蕲春县| 嫩江县| 定边县| 涿州市| 汾西县| 寿宁县| 商河县| 邹平县| 江山市| 葫芦岛市| 武平县| 垣曲县| 财经| 萨迦县| 揭阳市| 利川市| 安化县| 凌海市| 米林县| 乳山市| 朔州市| 中山市| 资源县| 隆林| 柳林县| 涟源市| 安达市| 黄大仙区| 蒙阴县| 平定县| 陈巴尔虎旗| 雷州市|