国产探花免费观看_亚洲丰满少妇自慰呻吟_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>

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

圖片精選

主站蜘蛛池模板: 思茅市| 九江县| 枣阳市| 弋阳县| 石嘴山市| 方山县| 深水埗区| 迭部县| 建瓯市| 同仁县| 武定县| 碌曲县| 宜君县| 富阳市| 会理县| 宁阳县| 南丰县| 朔州市| 民乐县| 广水市| 北辰区| 同仁县| 红桥区| 郸城县| 双柏县| 温宿县| 铜川市| 呈贡县| 营山县| 壤塘县| 华坪县| 瓮安县| 冕宁县| 菏泽市| 巴塘县| 大名县| 澳门| 宣武区| 呼图壁县| 渝北区| 通榆县|