關于速度動畫的問題,沒反應
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>
<style>
body,div,span{
?? ?padding:0;
?? ?margin:0;
}
#div1{
?? ?width:300px;
?? ?height:400px;
?? ?background:#39C;
?? ?position:relative;
?? ?top:100px;
?? ?left:-200px;
}
#div1 span{
?? ?width:33px;
?? ?height:110px;
?? ?background:#3CF;
?? ?position:absolute;
?? ?top:150px;
?? ?left:200px;
?? ?font-family:"微軟雅黑";
?? ?color:#FFF;
?? ?font-weight:bold;
}
</style>
<script>
window.onload=function(){
? var oDiv=document.getElementById("div1");
? oDiv.onmouseover=function(){
??? slMove(0);
? }
? oDiv.onmouseout=function(){
??? slMove(-200);
? }
}
var timer=null;
function slMove(target){
? clearInterval(timer);
? var oDiv=document.getElementById("div1");
? timer.setInterval(function(){
?? ??? var speed=0;
?? ???? if(oDiv.offsetLeft > target){
?????????? speed=-10;
?????????? }else{
?????????? speed=10;
??????? }
?? ??? if(oDiv.offsetLeft==target){
?? ???? clearInterval(timer);
? }else{
?? ?? oDiv.style.left=oDiv.offsetLeft+speed+'px';
?? ?? }
?? ?? },50)
}
</script>
<body>
<div id="div1"><span style="text-align:center" id="water">W<br />A<br />T<br />E<br />R<br /> </span></div>
</body>
</html>
看了教程后,沒看代碼,自己寫了一遍,然后檢查了幾遍,結果運行沒反應,和原版的對照著看,也沒發現什么問題,哪位可以幫忙解答下
2017-03-11
把timer.setInterval(function()里的.改成=,timer=setInterval(function()
2017-03-11
timer不是一個對象,而且也不是一個function,而且是放計時器的,用=號,