You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

41 lines
848 B

  1. import $ from 'jquery';
  2. class IHKSidebar {
  3. constructor(sidebar) {
  4. this.sidebar = sidebar.addClass('initiated');
  5. this.timer = null;
  6. const observer = new ResizeObserver((entries) => {
  7. this.handleResize();
  8. })
  9. observer.observe(sidebar.get(0));
  10. $(window).on('resize', () => {
  11. this.handleResize();
  12. })
  13. }
  14. handleResize() {
  15. if (this.timer) {
  16. clearTimeout(this.timer);
  17. }
  18. this.timer = window.setTimeout(() => {
  19. if (this.sidebar.outerHeight() < $(window).height() - 40) {
  20. this.sidebar.addClass('sticky');
  21. }
  22. else {
  23. this.sidebar.removeClass('sticky');
  24. }
  25. }, 250)
  26. }
  27. }
  28. export default IHKSidebar;
  29. $('body').on('ihk-init dynamic-component-loaded', function () {
  30. $('.sidebar:not(.initiated)').each(function(i) {
  31. new IHKSidebar($(this));
  32. });
  33. })