Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     function stikySocialLInks() {
  2.  
  3.         if ( $('.social-container').length ) {
  4.  
  5.             var currentScrollTop =  $(window).scrollTop(),
  6.                 viewportHeight = $(window).height(),
  7.                 article = $('.article'),
  8.                 articleOffsetTop = article.offset().top,
  9.                 socialContainer = $('.social-container'),
  10.                 articleEnd = articleOffsetTop + article.outerHeight() - socialContainer.outerHeight();
  11.  
  12.  
  13.             var socialLinksHeight = $('.social-container .social-links').outerHeight(),
  14.                 socialLinksOffsetTopBase = $('.article').offset().top + parseInt(socialContainer.css('padding-top'));
  15.  
  16.  
  17.             if ( currentScrollTop > viewportHeight / 2 - socialLinksHeight - 80 ) {
  18.  
  19.                 socialContainer.addClass('social-container__stiky');
  20.  
  21.             }
  22.  
  23.             if ( currentScrollTop > articleEnd ) {
  24.  
  25.                 socialContainer.removeClass('social-container__stiky').addClass('social-container__bottom');
  26.  
  27.             } else if ( currentScrollTop > articleOffsetTop ) {
  28.  
  29.                 socialContainer.addClass('social-container__stiky').removeClass('social-container__bottom');
  30.  
  31.             } else {
  32.  
  33.                 socialContainer.removeClass('social-container__stiky social-container__bottom');
  34.  
  35.             }
  36.         }
  37.  
  38.     }
  39.  
  40.     stikySocialLInks();
  41.  
  42.     $(window).on('scroll', function() {
  43.  
  44.         stikySocialLInks();
  45.  
  46.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement