tags:

views:

549

answers:

2

Does anybody know why the following code only has effect in FF?

$(document).ready(function() {
    $('#powerSearchSubmitButton').click(function() {
        startLoad();
    });
});

function startLoad() {
    $('.message').each(function(i) {
        $(this).animate({ opacity: 0 }, 500);           
    });
};
+1  A: 

Try adding 'return false;' to your click function. I set up a demo on my site and it works fine in IE6 and Opera.

sanchothefat
But if I return false, the form won't submit anymore..
borisCallens
Also, thanks for going the length of hosting a demo page
borisCallens
No problem, sorry I couldn't tell if that's what you needed to do. You've got the answer now anyway - just submit via javascript once all the animations are finished.
sanchothefat
+1  A: 

*Update**

Example here http://pastebin.me/4937b07714655 of 1 option which is to keep a count of the messages and run the animation callback only on the last message.


why dont you return false from the click or event.preventDefault() and in the animation callback submit the form

$(document).ready(function() {
    $('#powerSearchSubmitButton').click(function(ev) {
        startLoad();
        ev.preventDefault();
    });
});

function startLoad() {
    var $messages=$('.message');
    var count=$messages.length -1;
    $messages.each(function(i) {
       $(this).animate({ opacity: 0 }, 500, i == count ? submitForm:null);           
    });
};

function submitForm(){
     $('#yourForm').submit();
}
redsquare
Great idea, I'll come back with feedback when I got to it :)
borisCallens
By attaching a submitForm to the callback from each .message, I would get a number of submits.Can I somehow implement a callback from the entire startLoad function (I should rename it to animateLoad or something)
borisCallens
boris a number of ways you could count the number of items $('.message').length and keep a counter so you know ehn the last one has fired and then call the submitForm event. You could even use a setTimeout after 750ms say when you can be sure 99% of the animation is done. See which one works best
redsquare
errr I'll clarify in my answer!
redsquare
Thanks, I went with the count and a isSubmitted toggle. the count is what you described, the isSubmitted toggle to prevent double submits.
borisCallens