I'm practicing parallax, so during the scroll i need element's offsetTop and height. And i know, that it's triggers layout each time, when you "get" this style properties, so it's affects overall perfomance. I decided to set custom attributes for each element with function and update it on window resize:
function setAttrs() {
$sections.each(function() {
var offsetTop = $(this).offset().top,
height = $(this).height();
$(this).attr({"data-offset": offsetTop, "data-height": height});
});
}
setAttrs();
$(window).on("resize", function() {
setAttrs();
});
So, my question is - does attribute getter inside scroll handler affects perfomance somehow? Something like this:
var height = $(this).attr("data-height");
I'm sort of 90% sure that this is good way, but i need to be sure.