原生JS实现图片左右轮播
本效果使用js实现,当图片移动到200像素后回到0像素再向右移动200像素一直左右移动,不需要marquee标签。
完整的HTML代码如下,保存到HTML文档打开可以查看效果:
<!DOCTYPEhtml>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>JS使图片左右移动_何问起</title>
<metacharset="utf-8"/>
<basetarget="_blank"/>
<style>a{color:blue;}</style>
</head>
<body>
<p>mag:</p><inputtype="text"id="pos"/><br/>
<inputtype="button"onclick="move()"value="开始"/>请点击按钮<br/>
<divstyle="position:relative;min-width:600px;min-height:120px;">
<imgid="img"style="position:absolute;left:100px;"src="http://hovertree.com/themes/hvtimages/hlogo.png"/>
</div>
<div><ahref="http://hovertree.com/h/bjaf/62ak7aig.htm">查看代码</a><ahref="http://hovertree.com">返回首页</a><ahref="http://hovertree.com/texiao/">更多特效</a></div>
<script>
varhovertreeStep,hovertreeTurn=true;
functionmove(){
varmag=parseInt(document.getElementById("img").style.left);
document.getElementById("pos").value=mag;
if(hovertreeTurn){
hovertreeStep=1;hovertreeTurn=false;
}
if(mag>200){
hovertreeStep=-1;
}
if(mag<1)
{
hovertreeStep=1;
}
document.getElementById("img").style.left=(mag+hovertreeStep)+"px";
window.setTimeout("move()",50);
}
</script>
</body>
</html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持毛票票!
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短