I have an update button on which I want to pull attention when updating my content. I am doing this with an animation color fade and adding some arrow characters.
When the animation is开发者_运维知识库 finished I want my CSS :hover states back.
Is this possible or do I lose the original CSS and do I have to reset these with jQuery'shover()
Fiddle: http://jsfiddle.net/K6fd2/
CSS
a.btn { padding: 5px 20px; color: white; background-color: #4188FB; }
a.btn:hover { background: #FFCC00;}
HTML
<a href="#" class="btn">Update</a>
<br /><br />
<a href="#" class="change">change content</a>
JS
var oriBtnTxt = $(".btn").html(); // store original text
$(".change").click(function() {
$(".btn")
.css("background-color","#FFCC00")
.html(oriBtnTxt + " »")
.animate({backgroundColor: "#4188FB"}, 2000, "swing", function() {
// set back hover state
$("a.btn:hover").css("background-color", "#FFCC00");
});
})
This may not be the most elegant solution, but you could try the following:
$(this).removeAttr('style');
within your $.animate()
callback function.
Edit: I suspect that you're losing your :hover
styles because $.animate()
uses inline styles, which are set after stylesheet rules are evaluated; thus they take precedence over defined styles within the stylesheet.
精彩评论