我爲一個「卷軸」製作了這個腳本,它應該在點擊向上或向下箭頭時向上或向下移動。但是,我有兩個問題:Javascript動畫無法正常運作
1)向上箭頭將其向下移動,向下箭頭向上移動它
2)執行一次後,我無法再次執行它,我收到一個錯誤,說它是無法解析「頂」。
任何想法爲什麼這可能會發生?我粘貼下面的所有代碼。它並不漂亮,但它包含了一切。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Tales of the Hartland: Homepage</title>
<style type="text/css">
/* ID DEFINITIONS */
#reelHolder {
height: 750px;
width: 800px;
overflow: hidden;
border: 1px solid gray;
position: relative;
left:50%;
margin-left:-400px;
}
#arrowDown {
z-index:auto;
position:relative;
left:87.4%;
}
#arrowUp {
z-index:auto;
position:relative;
}
#reel {
position: relative;
}
/*CLASS DEFINITIONS */
.banner {
position: relative;
left:50%;
margin-left:-600px;
}
.arrow {
width:50px;
height:50px;
}
.reeler {
width:600px;
height:300px;
position: relative;
left:50%;
margin-left:-300px;
margin-top:50px;
}
.break {
height:0px;
}
.bigBreak {
height:50px;
}
</style>
<script>
//REEL UP
function reelUp(elem) {
elem = document.getElementById(elem);
var down = 0;
var curLoc = elem.style.top;
function frame() {
down++
elem.style.top = down + curLoc + 'px';
if (down == 300)
clearInterval(id);
}
var id = setInterval(frame, 10) // draw every 10ms
}
//REEL DOWN
function reelDown(elem) {
elem = document.getElementById(elem);
var down = 0;
var curLoc = elem.style.top;
function frame() {
down++
elem.style.top = (-1 * down) + curLoc + 'px';
if (down == 300)
clearInterval(id);
}
var id = setInterval(frame, 10) // draw every 10ms
}
</script>
</head>
<body>
<img src="Banner.png" width="1200" height="150" alt="" class="banner"/>
<a id="arrowUp" class="arrow" href="javascript:reelUp('reel')">
<img src="arrowUp.png" alt=""/>
</a>
<a id="arrowDown" class="arrow" href="javascript:reelDown('reel')">
<img src="arrowDown.png" alt=""/>
</a>
<div id="reelHolder" class="centerDiv">
<div id="reel">
<img src="reel1.png" class="reeler" id="reel1"/>
<div class="break"></div>
<img src="reel2.png" class="reeler" id="reel2"/>
</div>
</div>
</body>
</html>
仍在尋求幫助! – SeargentGen 2015-02-07 20:55:00