我試着製作一個按鈕,從頁面的開始位置移動到頁面末尾的 。 例如 :一個按鈕 圖像乾淨的頁面重置JavaScript上的移動按鈕當他到達頁面末尾
(按鈕)[現在的按鈕需要在頁面上移動在同一行 結束頁面時,他會到那裏,他將「重置」和開始做一遍
(按鈕){他動>>>}(按鈕){移動>>>}(按鈕){他動>>>}(按鈕),在這裏重
,現在他將開始再次做同樣的任務
(按鈕){他的移動>>>}(按鈕){移動摹>>>}(按鈕){他動>>>}(按鈕),在這裏重
,並再次..
(按鈕){他動>>>}(按鈕){移動>> (按鈕){他的移動>>>}(按鈕)並在這裏重置
我沒有按鈕,移動的權利,但我不知道爲什麼它不停止,我真的不知道如何使它重置。
這是HTML
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<title>Moving Button Page</title>
<meta charset="UTF-8">
<script src="js/script.js"></script>
</head>
<body>
<button id="movingid" style="position: absolute;left: 0px;">i Am Moving Button</button>
<!-- <button id="moveit" onclick="move()" style="position:absolute;margin-right="5%"">Let Start Moving</button> -->
</body>
<footer>
</footer>
</html>
,這是JavaScript的
function doMove() {
var times = 10
var movingid = document.getElementById("movingid");
var leftpx = parseInt(movingid.style.left);
var i=0
if (i<=times) {
for(var i=0 ; i<=times ; i++){
console.log(i)
movingid.style.left = leftpx + 50 + 'px';
// clearInterval(stop);
}
}
else{
clearInterval(stop);
}
}
***我想複寫標題*** –
你可以回去編輯*你的問題btw - 它不是100%清楚你的要求。 –
Typo:'onclick =「move()」'帶有一個名爲'doMove()'的函數不正確 –