forum

Home / DeveloperSection / Forums / How to use the toggle function with click function?

How to use the toggle function with click function?

Jayden Bell 2483 06-Jun-2013
Hi Expert,

I like to create a animate when user click on a button.There are two animate function I like to do on click so I thought to use toggle function which swap between two function.

Now problem is if I use toggle function it doing the two animate function without click and also the button disappears.

$('#button').toggle(
    function() {
        $('#slider').stop().animate({"margin-right": '0'});
    },
    function() {
        $('#slider').stop().animate({"margin-right": '50'});
    }
);

Here slider is the div which animates.

How to do the animate functions alternatively every time when user click a button?

Thanks in advance. 

Updated on 06-Jun-2013

Can you answer this question?


Answer

1 Answers

Liked By