halfmoonui / halfmoon

Halfmoon is a highly customizable, drop-in Bootstrap replacement. It comes with three built-in core themes, with dark mode support for all themes and components.
https://www.gethalfmoon.com
MIT License
3.04k stars 118 forks source link

window.onscroll method not firing in js. #26

Closed appventor closed 4 years ago

appventor commented 4 years ago

Hello, I wanted to shrink the navbar on scroll by using js function

window.onscroll = function () { console.log("onscroll"); scrollFunction(); //handling navbar height according to scroll value from top using document.body.scrollTop() };

but it never gets triggered. is it because of page-wrapper? i dont get any error. Can you help me with this?

halfmoonui commented 4 years ago

This is a good question and you are on the right track. Halfmoon uses a page wrapper for the different sections and a content wrapper for the content. What you are actually scrolling is the content wrapper. So the following is a possible fix:

<div class="page-wrapper">
    <div class="content-wrapper" onscroll="scrollFunction()">
        ...
    </div>
</div>

Please note that since you mentioned hiding the navbar on scroll, the easiest way to do this is by removing the .with-navbar class from the page wrapper. Something like this:

function scrollFunction() {
    halfmoon.pageWrapper.classList.remove("with-navbar");
}

That will automatically hide the navbar and reposition your sidebar and content.

appventor commented 4 years ago

Ok thank you for the quick response. Its working as expected now.