I have the below function that works a treat, but instead of clicking the #featured li.block div to make the div spin; how would one make a link with a class button a.button? clickable to make the #featured li.block div divs spin?
$('#featured li.block div').click(function()
{
var f = function($this, count)
{
$this.animate({
top: "-=200"
}, 70, function() {
$this.css('top', '220px').animate({
top: "-=220"
}, 70, function() {
if (count > 0) {
count = count - 1;
f($this, count);
/*if(count == 0) {
if ($this.hasClass('showing')) {
$this.removeClass('showing').addClass('hiding').hide();
}
}*/
}
});
});
};
f($(this), 8);
});
Use a.button as the selector for the click handler and the original selector for the function invocation.
EDIT I couldn't get your code to work regardless of the selector with more than one inner DIV. Try this (bonus, it's simpler):
$('a.button').click(function()
{
var f = function($this, count)
{
$this.animate({
top: "-=200"
}, 70, function() {
$this.css('top', '220px').animate({
top: "-=220"
}, 70, function() {
if (count > 0) {
f($this, --count);
}
});
});
};
$('#featured li.block div').each( function(i) {
var $this = $(this);
setTimeout( function() {
f( $this, 8 );
}, i*100 ); // the ith div will start in i*100ms
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With