REELHERO REELHERO - 3 months ago 10
jQuery Question

script will animate but not toggle

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

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


it won't toggle http://toddheymandirector.com/index_mobile99.html but if I replace toggle with click it will slide down http://toddheymandirector.com/index_mobile88.html
what am I getting wrong?

Answer

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)