jQuery toggle backgroundPosition on hover?
This changes background position on hover, I want to return position to 0 0 on mouse out. How do I do it?
$("#love").hover(function 开发者_StackOverflow中文版() {
document.getElementById('love').style.backgroundPosition= "0 -19px";
});
In this situation, you should use CSS rather than JavaScript because it will be faster:
<style type="text/css">
#love {
background-position: 0 0;
}
#love:hover {
background-position: 0 -19px;
}
</style>
$("#love").hover(function () {
document.getElementById('love').style.backgroundPosition= "0 -19px";
},function () {
document.getElementById('love').style.backgroundPosition= "0 0";
});
Use power of jQuery
$("#love").hover(function () {
$(this).css('background-position', '0 -19px');
}, function() {
$(this).css('background-position', '0 0');
});
or it can be done just in css using :hover
精彩评论