I make a component like a scroller of pictures. When the div element is shifted in the for loop (changing the marginLeft), the div = offset does not occur (at the end of the loop, the div stupidly appears at the new point. How to make the div offset as if by frames (so that you can see the offset for each pixel) .

var el = document.getElementById("div2"); for(i=0; i<img_w; i++){ ml--; el.style.marginLeft = ml + "px"; } /* img_w - это размер картинки по ширине ml - это переменная в которой хранится текущее MarginLeft (по умолчанию ml=0) */ 

thanks in advance.

  • Java script works with a speed that is thousands of times faster than the response of the human eye to your drawing event :) here you need to do a snapshot via setTimeout, or use the animate function () - deivan_
  • Ok, I'll try. - FrancNet
  • @deivan is not even there, the DOM is not rendered until the end of the function usually. jsfiddle.net/oceog/mV44Q - zb '
  • And what's the problem with using jQuery for example the animate method - webkostya
  • ))) This is me for example $ ('button'). On ('click', function () {$ ('div'). Stop (). Animate ({marginLeft: 250})}) - webkostya

0