Guest User

Untitled

a guest
Dec 11th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. $.fn.isInViewport = function() {
  2. var elementTop = $(this).offset().top;
  3. var elementBottom = elementTop + $(this).outerHeight();
  4.  
  5. var viewportTop = $(window).scrollTop();
  6. var viewportBottom = viewportTop + $(window).height();
  7.  
  8. return elementBottom > viewportTop && elementTop < viewportBottom;
  9. };
  10.  
  11. $(window).on('resize scroll', function() {
  12. $('.color').each(function() {
  13. var activeColor = $(this).attr('id');
  14. if ($(this).isInViewport()) {
  15. $('#fixed-' + activeColor).addClass(activeColor + '-active');
  16. } else {
  17. $('#fixed-' + activeColor).removeClass(activeColor + '-active');
  18. }
  19. });
  20. });
Add Comment
Please, Sign In to add comment