Reputation: 5210
I have the following code which works great for hover transitions:
#main_nav a, #main_nav a:visited {
display: block;
width: 240px;
margin: 3px 0 0 10px;
padding: 3px 10px;
color: #808080;
background-color: #f2f2f2;
border: 1px solid #ccc;
border-radius: 5px;
transition: 0.3s all;
}
#main_nav a:hover, #main_nav a:active, #main_nav a.active {
width: 250px;
margin-left: 0;
color: #000;
text-decoration: none;
background-color: #fff;
}
However, when I use JavaScript to apply the class active
I would like it to immediately take the properties without firing the transition. I've been digging and can't find anything on this...
Here's a fiddle showing the issue: http://jsfiddle.net/7WsrY/
Upvotes: 0
Views: 80
Reputation: 123739
If you want to prevent it from happening you need to override the css transition applied by
#main_nav a
by placing a new rule as below, so that the transition is reset if class active
is applied, otherwise the anchor will inherit the transtion from the rule #main_nav a
:
#main_nav a.active {
transition:none;
}
Upvotes: 2