- 相關(guān)推薦
如何實(shí)現(xiàn)JavaScript的DIV塊來(lái)回滾動(dòng)效果
導(dǎo)語(yǔ):如何實(shí)現(xiàn)JavaScript的DIV塊來(lái)回滾動(dòng)效果呢?下面是小編給大家提供的代碼實(shí)現(xiàn)過(guò)程,大家可以參考閱讀,更多詳情請(qǐng)關(guān)注應(yīng)屆畢業(yè)生考試網(wǎng)。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<p id="xx" style=" position:relative;left:100px;width:100px;height:50px;border: solid 1px red;">腳本之家</p>
<script type="text/javascript">
function ls(){
var p=true;//開(kāi)關(guān),true開(kāi),false關(guān)
var xx=document.getElementById('xx');
var xxleft = parseInt(xx.style.left);
var speed = 20;
var t=setInterval(rollRight,speed);
//向左移動(dòng)
function rollLeft(){
if(p){
xxleft--;
xx.style.left = xxleft+'px';
if(xxleft <=0 ){
clearInterval(t);
t=setInterval(rollRight,speed);
}
}
}
//向右移動(dòng)
function rollRight(){
if(p){
xxleft++;
xx.style.left = xxleft+'px';
if(xxleft >= 300){
clearInterval(t);
t=setInterval(rollLeft,speed);
}
}
}
}
ls();
</script>
</body>
</html>
【如何實(shí)現(xiàn)JavaScript的DIV塊來(lái)回滾動(dòng)效果】相關(guān)文章:
如何使用javascript實(shí)現(xiàn)瀑布流及效果加載06-17
JavaScript簡(jiǎn)單實(shí)現(xiàn)放大鏡效果代碼02-21
JavaScript如何實(shí)現(xiàn)JSON.stringify03-07
如何使用JavaScript實(shí)現(xiàn)頁(yè)面定時(shí)跳轉(zhuǎn)04-02
如何使用JavaScript實(shí)現(xiàn)倒計(jì)時(shí)03-02
使用CSS3來(lái)實(shí)現(xiàn)滾動(dòng)視差效果的教程04-03
如何基于JavaScript實(shí)現(xiàn)本地圖片預(yù)覽08-10