Assuming I have an element with the style top: 5px
, and then I execute element.style.top = "5px";
, will the browser readjust its position and trigger a layout again? Or does it recognize that there is no need to change anything? (Is this behavior specified in W3C standards?)
What is the reason for this behavior?
I am configuring certain values based on scrolling. For instance, when the scrollTop
goes from 100 to 300, the top position of an element should transition from 25px
to 50px
.
If the user scrolls rapidly, moving from a scrollTop
of 285 to 310, it means that the element's top position will not reach exactly 50px
but rather end up at something like 48.125px
.
To solve this issue, I adjust all scroll values above 300 so that the element's top position remains fixed at 50px
.