本效果使用js實現,當圖片移動到200像素後回到0像素再向右移動200像素一直左右移動,不需要marquee標簽。
效果展示
完整的HTML代碼如下,保存到HTML文檔打開可以查看效果:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>JS使圖片左右移動_何問起</title>
<meta charset="utf-8" />
<base target="_blank" />
<style>a{color:blue;}</style>
</head>
<body>
<p>mag:</p><input type="text" id="pos" /><br />
<input type="button" onclick="move()" value="開始" />請點擊按鈕<br />
<div style="position:relative;min-width:600px;min-height:120px;">
<img id="img" style="position:absolute; left:100px;" src="http://hovertree.com/themes/hvtimages/hlogo.png" />
</div>
<div><a href="http://hovertree.com/h/bjaf/62ak7aig.htm">查看代碼</a> <a href="http://hovertree.com">返回首頁</a> <a href="http://hovertree.com/texiao/">更多特效</a></div>
<script>
var hovertreeStep, hovertreeTurn = true;
function move() {
var mag = 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>