• Resolved Anonymous User 15363885

    (@anonymized-15363885)


    hello
    I have a site that has a sticky header and i can’t get the plugin to work with my header.
    Is there a way to hide the simple banner when a user scrolls say 10px?

    THanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author rpetersen29

    (@rpetersen29)

    Hi @berti09
    In the Website Custom Javascript section something like this should work:

    window.onscroll = function() {myFunction()};
    
    function myFunction() {
      if (document.body.scrollTop > 10 || document.documentElement.scrollTop > 10) {
        document.getElementById("simple-banner").setAttribute("style", "display:none;");
      } else {
        document.getElementById("simple-banner").setAttribute("style", "display:block;");
      }
    }
    
    Thread Starter Anonymous User 15363885

    (@anonymized-15363885)

    Thanks for this.
    I was trying to get it to stay hidden once a user scrolls down, rather than appear about again when they scroll up, like some cookie banners do…
    Is this easy to achieve?

    • This reply was modified 6 years ago by Anonymous User 15363885.
    Plugin Author rpetersen29

    (@rpetersen29)

    Shouldn’t be too hard to implement. You can look here, https://stackoverflow.com/questions/14573223/set-cookie-and-get-cookie-with-javascript, for an example.
    Essentially once the code is set up you would do something like

    
    window.onscroll = function() {myFunction()};
    
    function myFunction() {
      if (document.body.scrollTop > 10 || document.documentElement.scrollTop > 10) {
        document.getElementById("simple-banner").setAttribute("style", "display:none;");
        setCookie('simple-banner-cookie','testcookie',7);
      }
    }
    
    var x = getCookie('simple-banner-cookie');
    if (x) {
        document.getElementById("simple-banner").setAttribute("style", "display:none;");
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘hide on scroll’ is closed to new replies.