简体   繁体   English

Bootstrap NAV在手机中折叠或展开时为颜色设置样式的方式

[英]Bootstrap NAV way to style color when is collapsed or expanded in mobile

I'm dealing with bootstrap to style the navbar Ok, i can style perfectly for desktop or mobile in his initial state. 我正在处理引导程序来设置导航栏样式,好吧,我可以在其初始状态下完美地为台式机或移动设备设置样式。

The problem comes when i try to style on mobile in his expanded and collapsed state. 当我尝试在他的展开和折叠状态下为手机设置样式时,就会出现问题。

Here is a Codepen example, where you can see and example where i can touch the burguer and even the UL. 这是一个Codepen示例,您可以在其中看到我可以触摸到汉堡甚至UL的示例。

But, how can i change the logo color and the navbar background color ?? 但是,如何更改徽标颜色和导航栏背景颜色? The others were easy because there got class via jQuery. 其他方法很简单,因为通过jQuery获得了课程。

Hope someone can help me. 希望可以有人帮帮我。 ( Using CSS & JS ( with or without jQuery ) ) (使用CSS和JS(带有或不带有jQuery))

I try this but everything crashed 我尝试了这个,但是一切都崩溃了

 $('.navbar-toggle').toggle(function () { $(".navbar-header").addClass("opened"); $("#burguer").addClass("opened"); }, function () { $(".navbar-header").removeClass("opened"); $("#burguer").removeClass("opened"); }); 

You can use Bootstrap events on collapse : 您可以在崩溃时使用Bootstrap事件

JS: JS:

$('#bs-example-navbar-collapse-1').on('show.bs.collapse', function () {
  $('.navbar').addClass('mobile-opened');
  $('.navbar-brand').addClass('mobile-opened');
});

$('#bs-example-navbar-collapse-1').on('hide.bs.collapse', function () {
  $('.navbar').removeClass('mobile-opened');
  $('.navbar-brand').removeClass('mobile-opened');
});

CSS: CSS:

.navbar.mobile-opened {
  background: blue;
}
.navbar-brand.mobile-opened span {
  color: red;
}

If you want to change colors when animation is done just use shown instead of show and hidden instead of hide 如果你想改变颜色时,动画完成只用shown ,而不是showhidden ,而不是hide

CODEPEN CODEPEN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM