A more effective way of doing this? (Javascript)

Sysode

Front-End Developer
Dec 11, 2012
1,673
848
Just something quick, wondering if there is a more effective/efficent way of doing this? (It was just something I wrote up quickly)

Code:
$(window).scroll( function(){
  
    $('.featured-work ul.rig li').each( function(i) {
        var objBottom = $(this).position().top + $(this).outerHeight();
        var windowBottom = $(window).scrollTop() + $(window).height();

      
        if( windowBottom > objBottom ){
            $(this).animate({'opacity':'1'},800);
        }
    });
});

The only improvement I can see is probably assigning a class with the animations and letting the CSS deal with the animating instead of the Javascript.. Leave improvements below (apologies if it's scruffy)
 

Users who are viewing this thread

Top