javascript - Bootstrap toggle menu expand on page load - Stack Overflow

I have a navbar with dropdowns that work perfectly with hover. But on smartphones, instead of tapping t

I have a navbar with dropdowns that work perfectly with hover. But on smartphones, instead of tapping to open the dropdown, I want it to open automatically as soon as the toggle menu button is tapped.

I've tried some snippets I've found around here but haven't managed to adapt any to my problem.

I have a navbar with dropdowns that work perfectly with hover. But on smartphones, instead of tapping to open the dropdown, I want it to open automatically as soon as the toggle menu button is tapped.

I've tried some snippets I've found around here but haven't managed to adapt any to my problem.

Share Improve this question asked Oct 1, 2014 at 23:42 smmfsmmf 131 gold badge1 silver badge6 bronze badges 3
  • Can you post the code that you already have in a fiddle so that we can see what is going wrong and what you want to do? – Garrett Kadillak Commented Oct 1, 2014 at 23:54
  • You can find the code here (jsfiddle/fyjj67z5). When you click on the menu, when it expands, I want the items from the dropdowns to be visible immediately. – smmf Commented Oct 2, 2014 at 0:22
  • Edited my answer. Sorry I misread the question ... – jme11 Commented Oct 3, 2014 at 10:22
Add a ment  | 

1 Answer 1

Reset to default 2

Just manually add the class "in" to the element with the collapse navbar-collapse classes in your markup.

<nav class="collapse navbar-collapse in" role="navigation">

From the Bootstrap documentation on the Collapse plugin:

Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class in.

EDIT:

Sorry, I misread the question. Here is a DEMO.

To open the submenus, @scooterlord is correct, but the trick is that you need to use the right event. If you try and add the open class to the elements with the dropdown class on the click event of the toggle, it won't work because the dropdowns are closed automatically when the navbar is toggled. So, you'll have to wait until the collapse is fully shown:

$('.collapse.navbar-collapse').on('shown.bs.collapse', function(){
    $('.dropdown').addClass('open');
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745224769a4617409.html

相关推荐

  • javascript - Bootstrap toggle menu expand on page load - Stack Overflow

    I have a navbar with dropdowns that work perfectly with hover. But on smartphones, instead of tapping t

    10小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信