• Resolved listeraro

    (@listeraro)


    Hi,
    I have made the changes according to your suggestion here;
    https://wordpress.org/support/topic/no-id-for-bottom-menu-element/
    However there is an error on the Browser console;
    (index):5166 Uncaught TypeError: Cannot read properties of null (reading ‘style’)
    at window.onscroll ((index):5166:46)
    Is is about this CSS style:
    .style.bottom = “-50px”;

    Could you please check my code and tell me what I did wrong?

    CSS

    #wp-bottom-menu{
      position: fixed;
      bottom: 0;
      width: 100%;
      transition: bottom 0.3s;
    }

    JAVA

    /*wp-bottom-menu-hide-show-on-scroll*/
    function wpb_hook_javascript_footer() {
        ?>
            <script>
              var prevScrollpos = window.pageYOffset;
    window.onscroll = function() {
    var currentScrollPos = window.pageYOffset;
      if (prevScrollpos > currentScrollPos) {
        document.getElementById("wp-bottom-menu").style.bottom = "0";
      } else {
        document.getElementById("wp-bottom-menu").style.bottom = "-50px";
      }
      prevScrollpos = currentScrollPos;
    }
            </script>
        <?php
    }
    add_action('wp_footer', 'wpb_hook_javascript_footer');

    Thank you

    • This topic was modified 2 years, 1 month ago by listeraro.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Liquid Themes

    (@liquidthemes)

    Hi @listeraro ,

    1. Try, increasing the priority: add_action('wp_footer', 'wpb_hook_javascript_footer', 20);
    2. Try, check the getElementById data is not null. if ( document.getElementById("wp-bottom-menu") !== null ){ // your code }
    Thread Starter listeraro

    (@listeraro)

    Hi,
    The priority was the right solution.
    It fixed the issue.
    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Scroll to hide/Show’ is closed to new replies.