javascript - Fade elements in on scroll with Jquery -
i creating timeline of events on website, , trying each element (with class '.event') fade in scroll down through timeline. having issues - fade in @ same time rather individually.
any ideas why? in advance!
$(document).ready(function() { /* every time window scrolled ... */ $(window).scroll( function(){ /* check location of each desired element */ $('.event').each( function(i){ var bottom_of_object = $(this).position().top + $(this).outerheight(); var bottom_of_window = $(window).scrolltop() + $(window).height(); /* if object visible in window, fade it */ if( bottom_of_window > bottom_of_object ){ $(this).animate({'opacity':'1'},500); } }); });
});
based on jsfiddle seems linked styling and/or markup issue.
here's updated version of jsfiddle works code , markup: http://jsfiddle.net/2ymn4/2/. messes layout little bit, might need rethink structure, points in right direction. main change got started working switching .event
class relatively positioned. removing second .posts-timeline
article , .posts
div.
.event { position: relaive; opacity: 0; left: 50%; width: 210px; z-index: 100; min-height: 100px; }
Comments
Post a Comment