zutrinken / bleak

Ghost Theme
https://bleak.peteramende.de
MIT License
535 stars 130 forks source link

js doesn’t reload #69

Closed moeenxyz closed 3 years ago

moeenxyz commented 4 years ago

Hello, I use a .js file in order to stick the navbar to the top of screen after scroll, it works fine when the page load, but e.g. when I go to a post and then click on site title to go back to home page, the js doesn't relaod and therefore don't work. how should I reload it? I try to put the script in script.js but nothing changed.

moeenxyz commented 4 years ago

@zutrinken can you please help me about this?

moeenxyz commented 4 years ago
  window.addEventListener('scroll', stickynav);
var navbar = document.getElementById("nav");
var sticky = nav.offsetTop;

function stickynav() {
  if (window.scrollY > sticky) {
    navbar.classList.add("stickynav")
    navbar.classList.remove("navbottom")
  } else {
   navbar.classList.add("navbottom")
    navbar.classList.remove("stickynav");
  }
}
stickynav();

my code is like this, I changed the reload function as this:

function reload() {
        grid();
        ajaxLinkClass();
        highlight();
        gallery();
        video();
        comments();
        stickynav();

    }

but it doesn't work.

zutrinken commented 4 years ago

Can't test it at the moment, but looks like var navbar and var sticky are undefined after reload. Also the EventListener probably has to go into the reload function, but separately.