0
獲取錯誤,說明遞歸過多。實際上必須移動圖像。即使我試圖清除超時,它也會給出相同的錯誤。image.style.left無法正常工作javascript
注:我發現the_image.style.left沒有移動圖像。
<!DOCTYPE HTML>
<html>
<head>
<style>
.image_style{left:x}
</style>
<script>
var the_timer, x_position = 0, my_image;
function move_image(){
my_image = document.getElementById("imag");
x_position = x_position+1;
my_image.style.left = x_position;
the_timer = setTimeout(move_image(), 200);
}
</script>
</head>
<body onclick="move_image()">
<img src = "desert.jpg" id = "imag"
style="position:obsolute; width:300px; height:400px; left:0">
<script>
my_image = document.getElementById("imag");
alert(my_image.style.left);
</script>
</body>
</html>
'position:obsolute;'to'position:absolute;'。 – choz
你有一個錯字。它的'絕對'不'絕對' –
它似乎工作https://fiddle.jshell.net/attp1qcx/ my_image.style.left是0px像它應該是 – Roysh