Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Navigation displays block after multiple resizes

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #234957
    Jtwa11
    Participant

    When I resize the screen everything works correctly. But once I resize again, it doesn’t work the way I want it to.

    The navigation li appears as block elements when I want them to display none unless I click on menu.

    http://codepen.io/Jtwa/pen/WQPzVB?editors=001

    #234962
    Shikkediel
    Participant

    Like this?

    Demo

    What you describe happens because .show() adds display: block as inline style. And it’s overriding the CSS you defined for it with that. I’ve just put a .hide() in the else condition. Also cached the $('nav ul') selector since it’s used quite a few times.

    #234993
    Jtwa11
    Participant

    Perfect. Thank you for the help

    #235287
    rocksmethew
    Participant

    function throttle (callback, limit) {
    var wait = false; // Initially, we’re not waiting
    return function () { // We return a throttled function
    if (!wait) { // If we’re not waiting
    callback.call(); // Execute users function
    wait = true; // Prevent future invocations
    setTimeout(function () { // After a period of time
    wait = false; // And allow future invocations
    }, limit);
    }
    }
    }

    $(window).on(‘resize’, throttle(yourResizeFunction, 200))

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.