S
S
Skrolea2016-06-25 11:29:56
JavaScript
Skrolea, 2016-06-25 11:29:56

Why does the menu immediately collapse?

Made a hamburger menu that opens at all resolutions. But there was a problem, the menu, when pressed, opens and immediately closes.
Working example (more precisely, not working)

.navbar-toggle {
  z-index: 999;
  display: block;
  width: 32px;
  height: 32px;
  margin-right: 15px;
  background: transparent;
  border: none;
}
.navbar-toggle:hover,
.navbar-toggle:focus,
.navbar-toggle:active {
  outline: none;
}
.navbar-toggle.is-closed,
.navbar-toggle.is-open {
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
}
.navbar-toggle.is-closed:before {
  content: '';
  display: block;
  width: 100px;
  font-size: 14px;
  color: #fff;
  line-height: 32px;
  text-align: center;
  opacity: 0;
  -webkit-transform: translate3d(0,0,0);
  -webkit-transition: all 0.35s ease-in-out;
}
.navbar-toggle.is-closed:hover:before {
  opacity: 1;
  display: block;
  -webkit-transform: translate3d(-100px,0,0);
  -webkit-transition: all 0.35s ease-in-out;
}
.navbar-toggle.is-open:before {
  content: '';
  display: block;
  width: 100px;
  font-size: 14px;
  color: #fff;
  line-height: 32px;
  text-align: center;
  opacity: 0;
  -webkit-transform: translate3d(0,0,0);
  -webkit-transition: all 0.35s ease-in-out;
}
.navbar-toggle.is-open:hover:before {
  opacity: 1;
  display: block;
  -webkit-transform: translate3d(-100px,0,0);
  -webkit-transition: all 0.35s ease-in-out;
}


/******/
 .navbar-header {
        float: none;
    }
    .navbar-toggle {
        display: block;
    }
    .navbar-collapse {
        border-top: 1px solid transparent;
        box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
    }
    .navbar-collapse.collapse {
        display: none!important;
    }
    .navbar-nav {
        float: none!important;
        margin: 7.5px -15px;
    }
    .navbar-nav>li {
        float: none;
    }
    .navbar-nav>li>a {
        padding-top: 10px;
        padding-bottom: 10px;
    }

and
$(document).ready(function () {
  var trigger = $('.navbar-toggle'),    
     isClosed = false;

    trigger.click(function () {
      navtoggle_cross();      
    });

    function navtoggle_cross() {

      if (isClosed == true) {       
        trigger.removeClass('is-open');
        trigger.addClass('is-closed');
        isClosed = false;
      } else {        
        trigger.removeClass('is-closed');
        trigger.addClass('is-open');
        isClosed = true;
      }
  } 
 
});

What is the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
HamSter, 2016-06-25
@Skrolea

Add to styles

.navbar-collapse.collapse.in {
        display: block!important;
    }

The code works, but the styles for .in don't!

A
A person from Kazakhstan, 2016-06-25
@LenovoId

where can you see it in action?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question