Questions about the sample code in Chapter 10 of the Art of JavaScript DOM programming?

< H1 > this code is extracted from page 192 of Chapter 10 of the Art of Javascript DOM programming Edition 2 < / H1 >

what is the function of the penultimate line variable movement? Only the time function can be run. I don"t see where this variable is used. Page 192 says that the incorrect animation is caused by global variables and does not know how to affect it

< H2 > the code is as follows: moveElement.js < / H2 >
function moveElement(elementID,final_x,final_y,interval) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);

  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);

  if (xpos == final_x && ypos == final_y) {    //
    return true;
  }

  if (xpos < final_x) {
    xposPP;
  }
  if (xpos > final_x) {
    xpos--;
  }
  if (ypos < final_y) {
    yposPP;
  }
  if (ypos > final_y) {
    ypos--;
  }
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
  var repeat = "moveElement(""+elementID+"","+final_x+","+final_y+","+interval+")";  
  movement = setTimeout(repeat,interval); 
  //
}

Thank you for your guidance!

May.05,2022

Save the retarder handle, which is used to clear the retarder. If it is not cleared, there will be a memory leak

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a07f-4076a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a07f-4076a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?