sticky.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. (function() {
  2. 'use strict'
  3. let stickyElement = $(".sticky"),
  4. stickyClass = "sticky-pin",
  5. stickyPos = 66, //Distance from the top of the window.
  6. stickyHeight;
  7. ///Create a negative margin to prevent content 'jumps':
  8. stickyElement.after('<div class="jumps-prevent"></div>');
  9. function jumpsPrevent() {
  10. stickyHeight = stickyElement.innerHeight();
  11. stickyElement.css({ "margin-bottom": "-" + stickyHeight + "px" });
  12. stickyElement.next().css({ "padding-top": +stickyHeight + "px" });
  13. };
  14. jumpsPrevent(); //Run.
  15. //Function trigger:
  16. $(window).on('resize', function() {
  17. jumpsPrevent();
  18. });
  19. //Sticker function:
  20. function stickerFn() {
  21. let winTop = $(window).scrollTop();
  22. //Check element position:
  23. winTop >= stickyPos ?
  24. stickyElement.addClass('stickyClass') :
  25. stickyElement.removeClass('stickyClass') //Boolean class switcher.
  26. };
  27. stickerFn(); //Run.
  28. $(window).on('scroll',function() {
  29. stickerFn();
  30. });
  31. $('.app-sidebar').on('scroll', function() {
  32. let s = $(".app-sidebar .ps__rail-y");
  33. if (s[0].style.top.split('px')[0] <= 60 ) {
  34. $('.app-sidebar').removeClass('sidemenu-scroll')
  35. } else {
  36. $('.app-sidebar').addClass('sidemenu-scroll')
  37. }
  38. })
  39. })();