how to use scrollIntoView on dynamic HTML Elements
Hey,
in my script I am adding div elements dynamically to the DOM. After creation I want the browser to scroll them into view using JS function scrollIntoView.
The problem is that calling scrollIntoView right after calling document.body.appendChild(newElement) doesn't work.
Several times, this genre of problem can be solved with a setTimeout to execute the scroll some milliseconds after the end of the script. Still the page has to can scroll !
Several times, this genre of problem can be solved with a setTimeout to execute the scroll some milliseconds after the end of the script. Still the page has to can scroll !
Thanks, setting Timeout solved my problem but is there no better solution for that?
«Delaying the execution (even by 0 miilliseconds) allows screen updates to occur before the processing begin !» It's not necessary a bad solution ! Read, for example, this page «Processing vs Responsiveness».
Bookmarks