Archive for November, 2018

If in view

Check if an element is in view using only JQuery.
A sort of poor man’s Waypoints.

Demo with sections.

$(window).on('load scroll', function() {
  $('.element').each(function() {
    if ( $(this).offset().top <= ($(window).scrollTop() + $(window).height()/2)) {
     // in view (in the upper half of the screen)
    } else {
     // not in view
    }
  });
});