$('img.questSign').hover( function() {
$('img.questSign').attr('src', '/media/quest-sign-small-hover.png');
},
function(){
$('img.questSign').attr('src', '/media/quest-sign-small.png');
});
This code works quite awesome, when the page has been loaded freshly. But after a while it seems to be stop working. The picture does not change on hover.
ADDITION: I ran a long-term test with all major browsers and it seems that this very special problem only appears 开发者_StackOverflow中文版in the new Firefox 5 beta. Problem fixed with new Firefox Update
Try this:
$('img.questSign').hover(function() {
$(this).attr('src', '/media/quest-sign-small-hover.png');
}, function() {
$(this).attr('src', '/media/quest-sign-small.png');
});
Your old code would misbehave with multiple img.questSign
s on the page.
You may want to use a timeout like this:
$('img.questSign').hover(function () {
clearTimeout($(this).data('timeout'));
$(this).attr('src', '/media/quest-sign-small-hover.png');
}, function () {
var e = $(this).data('timeout', setTimeout(function () {
e.attr('src', '/media/quest-sign-small.png');
}, 3000)); // 3 sec
});
精彩评论