我试图写一点Javascript将会拍摄一个图像(目前,它只是一个测试图像500x400说“这是一个测试”),并减少宽度每隔一段时间,给人一种旋转的印象;然后,当宽度达到零时,宽度再次增加,使其看起来像它再次开放。setInterval增量增加/减少图像宽度
我已经写了一些不整洁的代码,需要大概;此刻,我只是想尝试一些工作,但我无法工作,任何人都可以帮忙?
<html>
<body>
<center>
<img src="sign.jpg" id="sign" width="500">
</center>
<script>
var decreasing=true;
var currentWidth=500;
var deltaWidth=5;
var myVar = setInterval(function(){ changeWidth() }, 500);
function changeWidth()
{
if(decreasing == true)
{
currentWidth=-deltaWidth;
document.getElementById("sign").width = currentWidth;
if(currentWidth<=0)
{
decreasing = false;
}
}
else
{
currentWidth=+deltaWidth;
document.getElementById("sign").width = currentWidth;
if(currentWidth>=500)
{
decreasing = true;
}
}
}
</script>
</body>
</html>
你期待这个http://jsfiddle.net/kishoresahas/j0m50uop/1/? –
@KishoreSahas我不认为你理解这个问题 – Jamiec