admin管理员组文章数量:1026416
I have been trying to modify django-oscar's navbar menu. /
What I can't figure out is that the menu 'browse store' remains open on page load on homepage but opens on click on all other pages. I can't figure out why that would happen. Is there a way to to make it open on hover and to add an <a>
tag on click?
This is the html template concerning the related part in oscar's documentation -
<div class="navbar-collapse primary-collapse collapse">
{% block nav_dropdown %}
<ul id="browse" class="nav navbar-nav">
<li class="dropdown active {% if expand_dropdown %}open{% endif %}">
<a href="#" class="dropdown-toggle" {% if not expand_dropdown %} data-toggle="dropdown"{% endif %}>
<span class="nav-line-1">Shop by</span><span class="nav-line-2"> Category</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu" data-navigation="dropdown-menu">
{% category_tree depth=2 as tree_categories %}
<li><a tabindex="-1" href="{% url 'catalogue:index' %}">{% trans "All products" %}</a></li>
{% if tree_categories %}
<li class="divider"></li>
{% for tree_category, info in tree_categories %}
{% if info.has_children %}
<li class="dropdown-submenu">
<a tabindex="-1" href="{{ tree_category.get_absolute_url }}">{{ tree_category.name }}</a>
<ul class="dropdown-menu">
{% else %}
<li><a tabindex="-1" href="{{ tree_category.get_absolute_url }}">{{ tree_category.name }}</a></li>
{% endif %}
{% for close in info.num_to_close %}
</ul></li>
{% endfor %}
{% endfor %}
{% endif %}
</ul>
</li>
{% block nav_extra %}
{% endblock %}
</ul>
{% endblock %}
</div><!-- /navbar-collapse -->
</div>
I have been trying to modify django-oscar's navbar menu. http://latest.oscarmerce./en-gb/
What I can't figure out is that the menu 'browse store' remains open on page load on homepage but opens on click on all other pages. I can't figure out why that would happen. Is there a way to to make it open on hover and to add an <a>
tag on click?
This is the html template concerning the related part in oscar's documentation -
<div class="navbar-collapse primary-collapse collapse">
{% block nav_dropdown %}
<ul id="browse" class="nav navbar-nav">
<li class="dropdown active {% if expand_dropdown %}open{% endif %}">
<a href="#" class="dropdown-toggle" {% if not expand_dropdown %} data-toggle="dropdown"{% endif %}>
<span class="nav-line-1">Shop by</span><span class="nav-line-2"> Category</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu" data-navigation="dropdown-menu">
{% category_tree depth=2 as tree_categories %}
<li><a tabindex="-1" href="{% url 'catalogue:index' %}">{% trans "All products" %}</a></li>
{% if tree_categories %}
<li class="divider"></li>
{% for tree_category, info in tree_categories %}
{% if info.has_children %}
<li class="dropdown-submenu">
<a tabindex="-1" href="{{ tree_category.get_absolute_url }}">{{ tree_category.name }}</a>
<ul class="dropdown-menu">
{% else %}
<li><a tabindex="-1" href="{{ tree_category.get_absolute_url }}">{{ tree_category.name }}</a></li>
{% endif %}
{% for close in info.num_to_close %}
</ul></li>
{% endfor %}
{% endfor %}
{% endif %}
</ul>
</li>
{% block nav_extra %}
{% endblock %}
</ul>
{% endblock %}
</div><!-- /navbar-collapse -->
</div>
Share
Improve this question
asked Nov 8, 2015 at 1:39
WutWutWutWut
1,2342 gold badges17 silver badges32 bronze badges
1 Answer
Reset to default 3The reason the home menu is doing that is because you have a atribute of open
on the <li class="dropdown active"
and on the other pages you don't, I just checked the site and that is forcing the menu open.
About your issue with it not behaving the same as the other pages and opening on click. This is becuase you forgot to add the data-toggle="dropdown"
on the a
tag just beneath <li class="dropdown active"
. The menu code should be as per the following on the homepage:
<ul id="browse" class="nav">
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Browse store<b class="caret"></b></a>
<ul class="dropdown-menu" data-navigation="dropdown-menu" style="width: 212px;">
<li><a tabindex="-1" href="/en-gb/catalogue/">All products</a>
</li>
<li class="divider"></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="/en-gb/catalogue/category/books_1/">Books</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="/en-gb/catalogue/category/books/fiction_2/">Fiction</a>
</li>
<li><a tabindex="-1" href="/en-gb/catalogue/category/books/non-fiction_4/">Non-Fiction</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li><a href="/en-gb/offers/">Offers</a>
</li>
</ul>
</li>
</ul>
You wanted to have it open on hover, i think yo ucan look into using JQuery and maybe checking if the menu has been hovered on and then adding the open class like this:
$('.dropdown').hover(function(){
$('.dropdown-toggle', this).trigger('click');
});
Good Luck
I have been trying to modify django-oscar's navbar menu. /
What I can't figure out is that the menu 'browse store' remains open on page load on homepage but opens on click on all other pages. I can't figure out why that would happen. Is there a way to to make it open on hover and to add an <a>
tag on click?
This is the html template concerning the related part in oscar's documentation -
<div class="navbar-collapse primary-collapse collapse">
{% block nav_dropdown %}
<ul id="browse" class="nav navbar-nav">
<li class="dropdown active {% if expand_dropdown %}open{% endif %}">
<a href="#" class="dropdown-toggle" {% if not expand_dropdown %} data-toggle="dropdown"{% endif %}>
<span class="nav-line-1">Shop by</span><span class="nav-line-2"> Category</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu" data-navigation="dropdown-menu">
{% category_tree depth=2 as tree_categories %}
<li><a tabindex="-1" href="{% url 'catalogue:index' %}">{% trans "All products" %}</a></li>
{% if tree_categories %}
<li class="divider"></li>
{% for tree_category, info in tree_categories %}
{% if info.has_children %}
<li class="dropdown-submenu">
<a tabindex="-1" href="{{ tree_category.get_absolute_url }}">{{ tree_category.name }}</a>
<ul class="dropdown-menu">
{% else %}
<li><a tabindex="-1" href="{{ tree_category.get_absolute_url }}">{{ tree_category.name }}</a></li>
{% endif %}
{% for close in info.num_to_close %}
</ul></li>
{% endfor %}
{% endfor %}
{% endif %}
</ul>
</li>
{% block nav_extra %}
{% endblock %}
</ul>
{% endblock %}
</div><!-- /navbar-collapse -->
</div>
I have been trying to modify django-oscar's navbar menu. http://latest.oscarmerce./en-gb/
What I can't figure out is that the menu 'browse store' remains open on page load on homepage but opens on click on all other pages. I can't figure out why that would happen. Is there a way to to make it open on hover and to add an <a>
tag on click?
This is the html template concerning the related part in oscar's documentation -
<div class="navbar-collapse primary-collapse collapse">
{% block nav_dropdown %}
<ul id="browse" class="nav navbar-nav">
<li class="dropdown active {% if expand_dropdown %}open{% endif %}">
<a href="#" class="dropdown-toggle" {% if not expand_dropdown %} data-toggle="dropdown"{% endif %}>
<span class="nav-line-1">Shop by</span><span class="nav-line-2"> Category</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu" data-navigation="dropdown-menu">
{% category_tree depth=2 as tree_categories %}
<li><a tabindex="-1" href="{% url 'catalogue:index' %}">{% trans "All products" %}</a></li>
{% if tree_categories %}
<li class="divider"></li>
{% for tree_category, info in tree_categories %}
{% if info.has_children %}
<li class="dropdown-submenu">
<a tabindex="-1" href="{{ tree_category.get_absolute_url }}">{{ tree_category.name }}</a>
<ul class="dropdown-menu">
{% else %}
<li><a tabindex="-1" href="{{ tree_category.get_absolute_url }}">{{ tree_category.name }}</a></li>
{% endif %}
{% for close in info.num_to_close %}
</ul></li>
{% endfor %}
{% endfor %}
{% endif %}
</ul>
</li>
{% block nav_extra %}
{% endblock %}
</ul>
{% endblock %}
</div><!-- /navbar-collapse -->
</div>
Share
Improve this question
asked Nov 8, 2015 at 1:39
WutWutWutWut
1,2342 gold badges17 silver badges32 bronze badges
1 Answer
Reset to default 3The reason the home menu is doing that is because you have a atribute of open
on the <li class="dropdown active"
and on the other pages you don't, I just checked the site and that is forcing the menu open.
About your issue with it not behaving the same as the other pages and opening on click. This is becuase you forgot to add the data-toggle="dropdown"
on the a
tag just beneath <li class="dropdown active"
. The menu code should be as per the following on the homepage:
<ul id="browse" class="nav">
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Browse store<b class="caret"></b></a>
<ul class="dropdown-menu" data-navigation="dropdown-menu" style="width: 212px;">
<li><a tabindex="-1" href="/en-gb/catalogue/">All products</a>
</li>
<li class="divider"></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="/en-gb/catalogue/category/books_1/">Books</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="/en-gb/catalogue/category/books/fiction_2/">Fiction</a>
</li>
<li><a tabindex="-1" href="/en-gb/catalogue/category/books/non-fiction_4/">Non-Fiction</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li><a href="/en-gb/offers/">Offers</a>
</li>
</ul>
</li>
</ul>
You wanted to have it open on hover, i think yo ucan look into using JQuery and maybe checking if the menu has been hovered on and then adding the open class like this:
$('.dropdown').hover(function(){
$('.dropdown-toggle', this).trigger('click');
});
Good Luck
本文标签: javascriptBootstrap Dropdown Active open on hover and link on clickStack Overflow
版权声明:本文标题:javascript - Bootstrap Dropdown Active open on hover and link on click - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745637841a2160558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论