0
$(window).scroll(function() {
//$(window).data('scrollEvent', function() {
var hT = $('.section1').offset().top,
   hH = $('.section1').outerHeight(),
   wH = $(window).height(),
   wS = $(this).scrollTop();
if (wS > (hT+hH-wH)){
     //I do something
     $(window).off("scroll");
}
}); 

Used .off() to fire the event only once. However, unable to trigger events for subsequent sections on the page any longer even after using $(window).on("scroll");

How can I best trigger events for all the sections on a page just once on scrolling

Denl45
  • 1
  • Possible duplicate of [Check if element is visible after scrolling](http://stackoverflow.com/questions/487073/check-if-element-is-visible-after-scrolling) – nizzik Feb 07 '17 at 07:27

1 Answers1

0

First you have to calculate the window.scrollTop

var wS = $(window).scrollTop();
$(window).scroll(function() {
  var hT = $('.section1').offset().top,
    hH = $('.section1').outerHeight(),
    wH = $(window).height();
  if (wS > (hT + hH - wH)) {
    console.log('scrolled');
    $(window).off("scroll");
  }
});
Parvez Rahaman
  • 4,269
  • 3
  • 22
  • 39