Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7947023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:18:52+00:00 2026-06-04T01:18:52+00:00

I have a bunch of functions that I fire up based on the width

  • 0

I have a bunch of functions that I fire up based on the width of the users view-port. I then tired to write some code that turned the functions on and off, when the user re-sizes.

However, this function stops working properly when I call it again.

It’s an expanding and collapsing menu for people on handheld devices, it uses the slideUp() and slideDown() jQuery functions to open and close each nested list.

It works fine when called initially, but then when the user scales their browser up and then back down, it’s broken. It tries to expand and collapse at the same time. Perhaps I’m making a mistake with the way I’m disabling this feature and calling it again? If you want me to explain what I want in more detail, just let me know.

Here’s my code:

/*  Load Nav Functions
 *  ------------------
 *  Checks the width of browser and only loads functions that are needed for that size
 */
var viewportWidth = $(window).width();  // store viewport width

if (viewportWidth < 1024 ) {                // fire up mobile nav if screensize small enough
    navToggle();        
    mobileNav();
    addMenuArrows();
    mobileSearchExpand();
} else {
    disableMobileNav();
}


/*  On Resize Events
 *  ----------------
 *  We only want the code to runs after a few milliseconds to improve performance:
 *  http://stackoverflow.com/questions/599288/cross-browser-window-resize-event-javascript-jquery
 */
var resizeTimer;                    // resetable var for the timeout

$(window).resize(function() {

clearTimeout(resizeTimer);      // start from zero

resizeTimer = setTimeout(function() {

    var viewportWidth = $(window).width();

    if (viewportWidth < 1024 ) {
        navToggle();
        mobileNav();
        addMenuArrows();
        resetFooterState();

    } else {
        disableMobileNav();
    } 


}, 100); // end of time out


});


/*
 * Hide Menu and Create Slide Function
 */
function navToggle() {

$('#mainNav').css({'display':'none'});

$('#navToggle').bind("click", function() {

    if (!$('#mainNav').hasClass('down')) {
        $('#mainNav').removeClass('up').addClass('down').stop().slideDown(400);
    } else {
        $('#mainNav').removeClass('down').addClass('up').stop().slideUp(400);
    }

    return false;

});

}

/*
 *  Slide Up or Down Depending on Click 
 */
function mobileNav() {

$('#mainNav li a').bind("click", function() {

    /* jump to parent list item */
    var listItem  = $(this).parent();

    /* store sub menu */
    var subNav    = listItem.children('ul');

    if (!subNav.hasClass('down')) {
        /* display the sub menu */
        subNav.removeClass('up').addClass('down').stop().slideDown(400);
    } else {
        /* hide the sub menu */
        subNav.removeClass('down').addClass('up').stop().slideUp(400);
    }

    return false;

});
}


 /*
 *  Add drop down arrows to menus with sub menus
 */
function addMenuArrows() {

$('#mainNav li').each(function() {

    var hasSubMenu = $(this).children('ul');

    if(hasSubMenu.length) {
        $(this).children('a').addClass('hasSubMenu');
    }

});

}

/*
 *   Reset menu for large display
 */
 function disableMobileNav() {

$('#mainNav').css({'display':'block'});

$('#navToggle').unbind();
$('#mainNav li a').unbind().removeClass('hasSubMenu');

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:18:53+00:00Added an answer on June 4, 2026 at 1:18 am

    It seem that you try to re bind event on user change browser size. It’s not good at all. But you can try .unbind() first then bind

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of functions that I created in some views that must
I have a bunch of functions that map to and from some codes defined
I have a bunch of overloaded functions that operate on certain data types such
I have a bunch of functions that work on Vectors, i.e. lists with type-enforced
I have a bunch of functions that look like this 'tea' : function (caller)
I have a bunch of functions that take in either an array of objects,
I have a bunch of javascript functions which depend on some server-side constants (such
So I want to have a bunch of functions that receive a state and
I have a python file that holds a bunch of functions that I'm continually
I am working on a project where I have a bunch of functions that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.