WordPress.org

Support

Support » Themes and Templates » part of jquery code is not working in wordpress

part of jquery code is not working in wordpress

  • I have developed a jquery code that should let the menu hide a bit when I scroll down, and reappear as soon as I start scrolling up.

    I had this perfectly working on my static html website, but I soon as I migrated it to wordpress, it stopped working. All my other js code works perfectly.. here is the part of code:

    $(document).ready(function(){
    
    $(window).scroll(function () {
    var prevScroll;
    var hidden = false;
        var currentScroll = $(this).scrollTop();
        if($("body").scrollTop() > 492){
        if (prevScroll) {
            console.log(currentScroll + "  " + prevScroll);
            console.log(hidden);
            if (currentScroll < prevScroll && hidden) {
                console.log('show');
                $("#header-wrap").animate({marginTop: '0px'}, 200);
                $("#menu").fadeIn("fast");
                hidden=false;
    
            } else if (currentScroll > prevScroll && !hidden) {
                console.log(hidden);
                console.log('hiding');
                $("#header-wrap").animate({marginTop: '-60px'}, 200);
                 $("#menu").fadeOut("fast");
                hidden=true;
            }
    
        } else if(!hidden){
            console.log('first time');
            $("#header-wrap").animate({marginTop: '-60px'}, 200);
            $("#menu").fadeOut("fast");
            hidden= true;
        }
        prevScroll = currentScroll;
      }
      else{
        if(hidden){
          console.log('show');
          $("#header-wrap").animate({marginTop: '0px'}, 200);
          $("#menu").fadeIn("fast");
          hidden=false;
        }
      }
    });
    });

    What is the problem with my code? I have it alongside all my js code in a script.js page.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘part of jquery code is not working in wordpress’ is closed to new replies.