Here is my code for a mouseover:
$('.caption').mouseover(function() {
$(this).fadeTo('slow',1);
$(this).css('color','#ddd').animate({'color': 'white'}, 500);
$(this).css('font-weight','bold');
});
$('.caption').mouseleave(function() {
$(this).fadeTo('slow',0.9);
$(this).css('color','white').animate({'color': '#ddd'}, 500);
$(this).css('font-weight','normal');
});
I have four boxes that this works with, all with the class .caption. I would like to make these actions rotate between the four of them with a certain number of seconds pause (say, 5) before moving to the next one. In other words, the mousedown effects (without having a mousedown), wait 5 seconds, mouseup effect, then move to the 2nd .caption, and do the same… etc.
Here is where I am, 45 minutes later or so.
function doRotate(num) {
var len = 3; // starts at 0
var index = num;
$('div .nav-piece').each = function() {
setInterval(function() {
$('div .nav-piece').eq(index).animate({
backgroundColor: "white"
}, 500);
}, 500);
setInterval(function() {
$('div .nav-piece').eq(index).animate({
backgroundColor: "#cfc4c3"
}, 500);
}, 500);
}
}
Here is the html:
<div id="nav-container">
<div id="piece1" class="nav-piece">
<div style="background-image: url('assets/bg_example.jpg'); background-repeat: no-repeat;">
<div class="caption overlay-top">Text example</div>
</div>
</div>
<div id="piece2" class="nav-piece">
<div style="background-image: url('assets/bg_example.jpg'); background-repeat: no-repeat;">
<div class="caption overlay-bottom">Text example</div>
</div>
</div>
<div id="piece3" class="nav-piece">
<div style="background-image: url('assets/bg_example.jpg'); background-repeat: no-repeat;">
<div class="caption overlay-top">Text example</div>
</div>
</div>
<div id="piece4" class="nav-piece">
<div style="background-image: url('assets/bg_example.jpg'); background-repeat: no-repeat;">
<div class="caption overlay-bottom">Text example</div>
</div>
</div>
</div>
doReady is called at document.ready.
Thanks!
First of all, you should use mouseenter/mouseleave or mouseover/mouseout in combination, not a mix of the two behaviors
This will achieve what you want. Each caption is executed in the callback from the prior animation. We use queue to put the element’s into the fx queue (the only place delay() works).
I’d throw this on fiddle, but fiddle seems to be in read-only mode today! 🙂