1

When I add overflow-y:scroll to the .nav styling the button to open the navigation requires 2 clicks. Change this to overflow: none and it only requires 1 click as intended when using the following jquery:

$(function(){
  var nav = $('.nav'),
  navBut = $('.navBut');

  navBut.click(function(){
  if(nav.width() === 0){
    nav.stop().animate({ width: '15%', opacity: '1.0' }, 300);
  } else {
    nav.stop().animate({ width: '0', opacity: '0.0' }, 300);
  }
});

Can anybody see why this would be the case or how I can solve this?

http://jsfiddle.net/9ubxyw0t/2/

5
  • what browser are you using? i just tried this in Chrome and it works fine with overflow set to "none" or "scroll" Commented Mar 3, 2015 at 1:03
  • 1
    I just tried it in Firefox and it works fine. In the latest version of Chrome it requires 2 clicks to open Commented Mar 3, 2015 at 1:11
  • I'm on the latest version of Chrome for the mac Commented Mar 3, 2015 at 1:13
  • I'm using Windows. Is it possibly a bug? And would there be a workaround in the jquery? Commented Mar 3, 2015 at 1:14
  • The answer below solved it! Thanks for your help Da Rod. Commented Mar 3, 2015 at 1:16

1 Answer 1

1

Rather than checking if the width of .nav is equal to 0, you need to check to see if it is less than or equal to 0.

Your original issue only seemed to effect certain browsers. It seems like some browsers would give the element a negative width when the overflow property was set to scroll. I guess this is just a cross-browser rendering inconsistency.

Updated Example

var nav = $('.nav'),
    navBut = $('.navBut');

navBut.on('click', function () {
    if (nav.width() <= 0) {
        nav.stop().animate({
            width: '15%',
            opacity: '1.0'
        }, 300);
    } else {
        nav.stop().animate({
            width: '0',
            opacity: '0.0'
        }, 300);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.