我正在尝试移动图像,仅此而已。我似乎无法弄清楚为什么它会给我带来问题。这个想法是让图像在旋转一组图像的同时一直呈方形。我会弄清楚那部分,但现在我根本无法让图像制作动画。
HTML:
<body>
<h1>Assignment 1</h1>
<hr>
<img id="img_num" src="images/img_num1.png" alt="Image."/>
<hr>
<a href="index.html">PAGE 1 | </a>
<a href="page2.html">PAGE 2</a>
<footer>Name | Student #</footer>
</body>
JS:
$(window).onload(function(event)
{
while(true)
{
$('#img_num').animate(
{"left": "+=50px"},
"slow");
}
});
CSS:
#img_num {
width: 250px;
height: 250px;
position: relative;
}
最佳答案
.onload
不是 jQuery 方法,请使用 .load()
;此外,while
循环似乎不是必需的
$(window).load(function(event) {
// while(true)
// {
$('#img_num').animate({
"left": "+=50px"
},
"slow");
// }
});
#img_num {
width: 250px;
height: 250px;
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<body>
<h1>Assignment 1</h1>
<hr>
<img id="img_num" src="http://placehold.it/300" alt="Image." />
<hr>
<a href="index.html">PAGE 1 | </a>
<a href="page2.html">PAGE 2</a>
<footer>Name | Student #</footer>
</body>
关于javascript - Jquery动画功能不移动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37648234/