Comments (7)
That active
class is certainly added by the system when the page is rendered and then there is CSS to make that active class appear, and then styles to make it look different.
I don't understand the other part... you want to show menus as "open" by default if they are active? Why? Wouldn't that cover up some of the page?
In terms of adding a class to the <li>
, you could do something like this in PHP ($currentLink
is a variable you set possibly from a $_SERVER
variable):
<li class="<?= $currentLink == '/about/' ? 'active' : '' ?>"><a href="/about/">About</a></li>
or same example but using AngularJS (currentLink
is something set from $location
, i.e. $scope.currentLink = $location.path()
):
<li ng-class="{ active: currentLink == '/about/' }"><a href="/about/">About</a></li>
from bootstrap-hover-dropdown.
Thanks for the feedback!
The part of setting the corresponding class to the
Let me elaborate, just looking at the top level list. I'll not include the submenu code.
Lets assume we have a list:
<u class="nav navbar-nav">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-target="#" href="/products/">Products</a></li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-target="#" href="/about/">About</a></li>
<ul>
Now, we access the page "About", then it looks like this:
<u class="nav navbar-nav">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-target="#" href="/products/">Products</a></li>
<li class="dropdown active"><a class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-target="#" href="/about/">About</a></li>
<ul>
active
is added to the list tag.
This entry has is own css style, so it is visible for the user where he is.
Now using your plugin, by hovering over "Products", the class open
is added to the products entry.
The result is, I have two highlighted entries.
What I try to achieve is to remove the active
class temporarily, as long the user hovers over other menu entries. When the hover is done, the active
class should be added again.
Another approach is to add ann additional class to the active list tag, while hovering, and remove it as soon the hover over the other entries is finished.
Hope this makes sense.
from bootstrap-hover-dropdown.
I think so, but why not use separate styles for active? There's no reason it shouldn't always show the active state, even if they're hovering over other items. For example, Bootstrap even has an active class, and it highlights the item blue, and the hover styles are light grey (in this screenshot, I'm hovering over the 2nd to bottom item and the top one is "active"):
from bootstrap-hover-dropdown.
I just setup an example here: http://www.bootply.com/RbT27Dlej6
As you can see, the "Dropdown" submenu is active and the submenu visible; fine.
But when I hover over "Contact", the "Dropdown" submenu remains, but should hide while hovering over "Contact".
from bootstrap-hover-dropdown.
This issue isn't with my plugin but with the other plugin you're using. You could make the background a solid for the submenu and then have the submenu have a higher z-index than the active and be done. You could fix this all with tweaking a couple lines of CSS on the other plugin.
from bootstrap-hover-dropdown.
Ok. Another approach without interfering any other plugins.
I'm just using your demo page: When the entry "Dropdown" has the class active
, while hovering over "Account", how can I disable the active
status for this time?
from bootstrap-hover-dropdown.
You would have to mess with my plugin. And it would require changing the JavaScript whereas the other plugin only requires you putting some styles in your own stylesheet.
You'd have to create a index of elements with active on them and take them off/put them back depending on if other menu items are open. It will be tricky, but you're welcome to fork and do that. It's not something I think needs to belong in this plugin tho.
from bootstrap-hover-dropdown.
Related Issues (20)
- Versions do not update on CDNJS.com HOT 6
- Hover is not working in Chrome Version 47.0.2526.80 m HOT 6
- demo site down? HOT 2
- Doesn't work on Firefox 43.0.4 on Windows 10 Professional. HOT 2
- Problem when navbar is collapsed HOT 4
- Problem with hover on <a> ? HOT 3
- Deactivate hover when in "mobile mode" HOT 4
- Mouseover inputbox's remembered value will close the nav
- invalid-meta bootstrap-hover-dropdown
- Can't toggle dropdown on touch devices unless using bootstrap's data-toggle="dropdown" HOT 1
- Hover works only sometimes HOT 5
- shown.bs.dropdown & hidden.bs.dropdown are not triggered HOT 2
- When the 'a' tag has child elements the hover doesnt always work because of the event.target HOT 12
- Can't seelct the top level nav item HOT 2
- Delay option for submenus
- Anchor element gets hidden HOT 1
- Padding and margin prevents openDropdown event
- Doesn't work on Firefox 57.0.2 (64-bit) HOT 2
- My hover silently fails... HOT 3
- Any chance to implement Bootstrap 5 support?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bootstrap-hover-dropdown.