Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify animate function with JQuery

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);
});
like image 826
Keith Donegan Avatar asked Dec 08 '25 09:12

Keith Donegan


1 Answers

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
    });
});
like image 79
tvanfosson Avatar answered Dec 09 '25 22:12

tvanfosson