關(guān)于速度動(dòng)畫(huà)的問(wèn)題,沒(méi)反應(yīng)
<!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>無(wú)標(biāo)題文檔</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>
看了教程后,沒(méi)看代碼,自己寫(xiě)了一遍,然后檢查了幾遍,結(jié)果運(yùn)行沒(méi)反應(yīng),和原版的對(duì)照著看,也沒(méi)發(fā)現(xiàn)什么問(wèn)題,哪位可以幫忙解答下
2017-03-11
把timer.setInterval(function()里的.改成=,timer=setInterval(function()
2017-03-11
timer不是一個(gè)對(duì)象,而且也不是一個(gè)function,而且是放計(jì)時(shí)器的,用=號(hào),