Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  2.  
  3. $(document).ready(function(){
  4.  
  5. var $element = $('#waypoint');
  6. waypoint($element);
  7.  
  8. function waypoint($element)
  9. {
  10. var hasTriggered = false;
  11. $(window).scroll(function() {
  12. var elementTop = $element.offset().top,
  13. elementHeight = $element.outerHeight(),
  14. windowHeight = getWindowHeight(),
  15. windowScroll = $(this).scrollTop();
  16.  
  17. if (windowScroll > (elementTop+elementHeight-windowHeight) && !hasTriggered){
  18. console.log('you have scrolled to the element ' + $element[0].id);
  19. hasTriggered = true;
  20. }
  21.  
  22. });
  23. }
  24.  
  25. function getWindowHeight()
  26. {
  27. var viewportHeight;
  28. if (document.compatMode === 'BackCompat') {
  29. viewportHeight = document.body.clientHeight;
  30. } else {
  31. viewportHeight = document.documentElement.clientHeight;
  32. }
  33. return viewportHeight;
  34. }
  35.  
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement