var hmbgButton = $('.fa-menu-font'); var contentWrapper = $('#content-wrapper'); var sidebarWrapper = $('#sidebar-wrapper'); function fToggleSidebar(){ contentWrapper.toggleClass('site-transform'); hmbgButton.toggleClass('fa-bars').toggleClass('fa-close'); sidebarWrapper.toggleClass('sidebar-site-tran'); } //generic throttle, with resize and scroll applied to it for calculations, tying it to requestanimation frame ;(function() { var throttle = function(type, name, obj) { obj = obj || window; var running = false; var func = function() { if (running) { return; } running = true; requestAnimationFrame(function() { obj.dispatchEvent(new CustomEvent(name)); running = false; }); }; obj.addEventListener(type, func); }; throttle ("scroll", "optimizedScroll"); throttle("resize", "optimizedResize"); })(); $sidebarTopText = $(".sidebar-top-text"); $sidebarMiddleText = $(".sidebar-middle-text"); $sidebarBottomText = $(".sidebar-bottom-text"); // handle event window.addEventListener("optimizedResize", function() { if($sidebarTopText.offset().top+$sidebarTopText.outerHeight() > $sidebarBottomText.offset().top) { $sidebarMiddleText.css("top","auto"); $sidebarMiddleText.css("position","relative"); $sidebarMiddleText.css("transform","none"); } if($sidebarMiddleText.offset().top+$sidebarMiddleText.outerHeight() > $sidebarBottomText.offset().top) { $sidebarBottomText.css("display","none"); } else { $sidebarBottomText.attr("style", ""); } }); $(window).load(function(){ if($sidebarTopText.offset().top+$sidebarTopText.outerHeight() > $sidebarMiddleText.offset().top) { $sidebarMiddleText.css("top","auto"); $sidebarMiddleText.css("position","relative"); $sidebarMiddleText.css("transform","none"); } if($sidebarMiddleText.offset().top+$sidebarMiddleText.outerHeight() > $sidebarBottomText.offset().top) { $sidebarBottomText.css("display","none"); } else { $sidebarBottomText.css("display","block"); } });