有关javascript的小问题~求高手帮忙。。万分感激!!
请问里面的if(elem.movement){clearTimeout(elem.movement);}是判断函数执行停止的语句吗?if(elem.movement)是否...
请问里面的if (elem.movement) { clearTimeout(elem.movement); }是判断函数执行停止的语句吗? if (elem.movement)是否等于if (elem.movement!=undefined)。。如果是的话为什么能在刚好执行到所需位置时为!=undefined呢???求高手赐教!!
不好意思! 忘记发代码了:
function moveElement(elementID,final_y,interval) {
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var ypos = parseInt(elem.style.top);
if (ypos < final_y) {
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if (ypos > final_y) {
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
} 展开
不好意思! 忘记发代码了:
function moveElement(elementID,final_y,interval) {
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var ypos = parseInt(elem.style.top);
if (ypos < final_y) {
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if (ypos > final_y) {
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询