<script type="text/javascript">
$(document).ready(function() {
$(".module .caption").hide();
$(".module").hover(function() {
$(this).find(".caption").slideDown().end().siblings('.module').addClass('under');
},function() {
$(this).find(".caption").slideUp().end().siblings('.module').removeClass('under').delay(10000);
});
});
</script>
This works great, except the .delay doesn’t work, is my syntax wrong? I’m just trying to accomplish haveing the .removeClass(“under”) delayed by a second or two when the mouse un-hovers. I don’t want to delay the slideUp.
Any ideas?
delay()works on thefxqueue by default.removeClassdoes not get added to any queues, so cannot be affected bydelay()without some changes.You can either:
removeClasscall to thefxqueue manuallysetTimeoutinstead.Solution 1 Note the reshuffling of
delayin the jQuery chain as well!:Solution 2:
Note that both solutions will give weird (but different) effects if someone mouse overs/ outs a few times. To solve the issues with #1, add
.stop().clearQueue()to the chain on mouse over. To solve #2, store a reference to the timeout, andclearTimeout(theVariable)on mouse over.