WordPress.org

Forums

part of jquery code is not working in wordpress (6 posts)

  1. zahidaoui
    Member
    Posted 11 months ago #

    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

  2. keesiemeijer
    moderator
    Posted 11 months ago #

  3. zahidaoui
    Member
    Posted 11 months ago #

    still no result keesiemeijer! any thoughts?

  4. keesiemeijer
    moderator
    Posted 11 months ago #

    What is it you've done?

    Can you post a link to your site where this script isn't working.

  5. zahidaoui
    Member
    Posted 11 months ago #

    my website isn't online yet! im still working locally..

  6. Andrew
    Forum moderator
    Posted 11 months ago #

    When you said

    still no result keesiemeijer! any thoughts?
    what did you do?

Reply

You must log in to post.

About this Topic