REELHERO REELHERO - 11 months ago 51
jQuery Question

script will animate but not toggle

I'm running a script that should toggle up and down

$('#movedown').toggle(function() {
$(".menu2").animate({top: '-=1512px'}, 500);
}, function() {
$(".menu2").animate({top: '+=1512px'}, 500);

it won't toggle but if I replace toggle with click it will slide down
what am I getting wrong?

Answer Source

You are using jQuery.toggle wrong,

.toggle( [duration ] [, complete ] )

Description: Display or hide the matched elements.

See: jQuery.toggle.

toggle is meant to be used to show/hide the matched elements, not switch between two functions as you are trying to use it.

From what I understand, you want to make an element "wobble" up and down?

This should work:

$(".menu2").animate({top: '-=1512px'}, 500).animate({top: '+=1512px'}, 500)