oDiv.style.left = oDiv.offsetLeft+10+'px';
window.onload=function(){
var oDiv=document.getElementById('div1');
oDiv.onmouseover=function(){
startMove();
}
}
var timer=null;
function startMove(){
var oDiv=document.getElementById('div1');
timer=setInerval(function({
? ? ? ? oDiv.style.left = oDiv.offsetLeft+10+'px';
? ? },30)
}
?oDiv.style.left = oDiv.offsetLeft+10+'px';在瀏覽器中報(bào)錯(cuò)導(dǎo)致無法生成動(dòng)畫效果是為什么
2016-12-19
setInerval不是這個(gè)
setInterval這個(gè)
2016-11-16
十分感謝
2016-11-15
函數(shù)體也有問題,我寫的JS部分代碼是這樣的
window.onload=function(){
var oDiv=document.getElementById("div1");
oDiv.onmouseover=function(){
startMove(0);
}
oDiv.onmouseout=function(){
startMove(-200);
}
}
var timer=null;//注意
function startMove(iTarget){
var oDiv=document.getElementById("div1");//注意
var speed=0;
if(oDiv.offsetLeft>iTarget){
speed=-10;
}
else{
speed=10;
}
clearInterval(timer);//清除定時(shí)器影響因素
timer=setInterval(function(){
if(oDiv.offsetLeft==iTarget){
clearInterval(timer);
}
else{
oDiv.style.left=oDiv.offsetLeft+speed+'px';//注意加上px
}
},30);
}
2016-11-15
第十行timer=setInerval(function({有個(gè)小錯(cuò)誤,應(yīng)該是timer=setInerval(function(){