0

help code gives no error

/*edit: I fixed the problem with it not moving, but now when it tries to clearInterval (move), it says move is not defined. */ this code is supposed to take an element and a number value, and move the element by the number's percent of 1000 along another element that is 792 pixels wide. When I run it I get no error, but the element doesn't move. Please help I've been trying for hours. function moveScrollers (id,distance) { id.style.visibility = 'visible'; i = 0; finalDistance = 0; var move = setInterval (movement (i, id, distance), 10); }; function movement (i ,id ,distance) { if (i == distance) { clearInterval (move); } else { speed = Math.ceil (Math.sqrt (distance - i)); i += speed increase = Math.ceil(1000/792*speed); finalDistance += increase; id.style.left = finalDistance + 'px'; console.log ('largba'); } };

7th Jul 2021, 2:30 AM
Blake Grass
Blake Grass - avatar
3 Antworten
+ 1
I'm sorry for the trouble anyone, but I believe the problem was that I accidently swapped i and distance when getting the difference, therefor my speed variable was NAN because it was negative.
7th Jul 2021, 1:24 PM
Blake Grass
Blake Grass - avatar
+ 1
does it have a position fixed relative or absolute set? If you can, share your code in playground.
7th Jul 2021, 4:14 AM
arturop200
arturop200 - avatar
0
Arturop it is set relative, but i dont want to share the entire code yet because it is an addition on one of my other codes, and i dont want to update the other until it actually works.
7th Jul 2021, 12:57 PM
Blake Grass
Blake Grass - avatar