Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.88 KB | None | 0 0
  1. $(function () {
  2.         let $scrollDoc,
  3.             $basketBtn = $('#vmCartModule-sticky-wrapper'),
  4.             $basketTop = $('#vmCartModule-sticky-wrapper').offset().top,
  5.             rightContainer = $('.container')[0].getBoundingClientRect().right,
  6.             widthDocument = document.documentElement.clientWidth,
  7.             widthContainer = $('.container').outerWidth();
  8.         let widthBtnBasket = $basketBtn.outerWidth();
  9.  
  10.  
  11.         $(window).scroll(function () {
  12.             $scrollDoc = $(window).scrollTop();
  13.  
  14.             if ($scrollDoc > $basketTop) {
  15.                 if (((widthDocument - widthContainer) / 2) > widthBtnBasket) {
  16.                     $basketBtn.css({
  17.                         'position': 'fixed',
  18.                         'left': (Math.ceil(rightContainer - 10)) + 'px',
  19.                         'top': 0,
  20.  
  21.  
  22.                     });
  23.                 } else {
  24.                     $basketBtn.css({
  25.                         'position': 'fixed',
  26.                         'right': 0,
  27.                         'top': 0,
  28.  
  29.  
  30.                     });
  31.                 }
  32.  
  33.  
  34.             } else {
  35.  
  36.                 $basketBtn.css('position', 'static');
  37.             }
  38.         });
  39.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement