我試圖根據按鈕觸發的某些值在上面的圖像上下滑動條。理想情況下,每次新的「開始」位置都是先前輸入的「結束」位置(除非有更好的方法)。這裏是低於
example imagejavascript動畫 - 使用上一個結束點的按鈕
我的代碼來完成大部分的我想要什麼,但我很想有欄中的每個按鈕點擊後的期望值之間的滑動順暢。謝謝!
<!DOCTYPE html>
<html>
</script>
</body>
</html>
<style>
#container {
width: 19px;
height: 186px;
position: relative;
background: clear;
margin: 0px;
}
#animate {
border: 1px solid white;
width: 32px;
height: 12px;
position: absolute;
background-color: #252525;
}
</style>
<body>
<p>
<button onclick="myMove(0 ,20)">Move to Orange</button>
<button onclick="myMove(20, 100)">Move to Green</button>
<button onclick="myMove(100, 155)">Move to Blue</button>
</p>
<div id ="container">
<img src="https://dl.dropboxusercontent.com/u/377009668/webGL/stuff/legendVertical.png" alt="Fit Map Legend" style="float:left">
<div id ="animate"></div>
</div>
<script>
function myMove(start, stop) {
var elem = document.getElementById("animate");
var id = setInterval(frame, 5);
function frame() {
if (start == stop) {
clearInterval(id);
} else {
start++;
elem.style.top = start + 'px';
}
}
}
</script>
</body>
</html>
爲什麼'null'在'myMove(NULL,5)'?? –