Milan Koyš Milan Koyš - 5 days ago 6
CSS Question

How can i add to value not set value

How can add an value of 50 not set the left attribute left to 50?

document.getElementById("myDiv").style.left = "50px";


I am trying to get a smooth animation effect for my picture slider.

Answer

You could parse the value and add some value to it.

document.getElementById("myDiv").style.left = 
    (parseInt(document.getElementById("myDiv").style.left, 10) + 50) + 'px';
Comments