Guest User

Untitled

a guest
Feb 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. ```js
  2. // @params
  3. // element - Element whose position is to be found
  4. // footerHeight - Height to subtract from window bottom in case of a fixed footer/overlay
  5. window.elementPositionByViewport = function(element, footerHeight) {
  6. var elementBottom, elementTop, screenBottom, screenTop;
  7.  
  8. if (footerHeight == null) {
  9. footerHeight = 0;
  10. }
  11.  
  12. elementTop = $(element).offset().top;
  13. elementBottom = elementTop + $(element).outerHeight();
  14.  
  15. screenTop = $(window).scrollTop();
  16. screenBottom = screenTop + window.innerHeight;
  17. screenBottom -= footerHeight;
  18.  
  19. if ((screenBottom > elementTop) && (screenTop < elementBottom)) {
  20. return 'visible';
  21. } else if (elementTop < screenTop) {
  22. return 'above';
  23. } else {
  24. return 'below';
  25. }
  26. };
  27. ```
Add Comment
Please, Sign In to add comment