I noticed that jQuery scroll binding for $ (window) .scroll tends to significantly reduce pages. For example, I have elements in the page change styles when I scroll through them using the following script:
$(window).scroll(function() {
var bottom_of_window = $(window).scrollTop() + $(window).height();
$('.ElementsToBeChanged').each(function() {
var bottom_of_object = $(this).offset().top + $(this).outerHeight();
if (bottom_of_window > bottom_of_object) {
}
});
});
It is clear that the laggy site, since it constantly works on scrolling, but I did not come across any alternative for triggering events when objects scroll. Such sites that trigger events on a scroll look pretty often; What do they use to circumvent this gap?
source
share