0

I have some div with scroll.

I want to do with javascript, that function will active when the scroll of the div will comes to element.

I want to do this without jQuery.

How can I do it?


example for source:

the div id=bb, is the element that when the scroll comes to, it will active the 'example' function

<div id=aa>  // this div have scrollbar
     <br><br><br><Br><br><br><br><br><br><br><br><br><br><Br><br><br><br><br>

     <div id=bb>this is the element that will active the function</div>

     <br><br><br><Br><br><br><br><br><br><br><br><br><br><Br><br><br><br><br>
</div>

this is the function that i want to active when the scroll comes to the element:

function example() {
     document.write('work!');
}
  • 1
    possible duplicate of [Check if element is visible after scrolling](http://stackoverflow.com/questions/487073/check-if-element-is-visible-after-scrolling) – benomatis Apr 22 '14 at 16:41

1 Answers1

0
window.onscroll = function() {
  var pos = window.pageYOffset;
  var b = getElementById("bb");
  var pos_bb = b.offset().top;
  if(pos == pos_show) {
      example();
  }          
}

try this, use pageYOffset;

  • I believe you want `pos == pos_bb` instead of `pos_show`. Also, this will only work if the scroll lines up exactly with the element, which might not happen. – Colin DeClue Apr 22 '14 at 17:30