GwtQuery - fadeIn one after another

346 Views Asked by At

I want to add fade-in animation for couple of widgets one after another. I reviewed the doc, but it only does first fade-in.

$(myWidget1).fadeIn(new Function(){
      public boolean f(Event e){
            //tried to add the second fade-in for myWidget2, but no result 
            return true;
      }
});

How do I achieve fade-in one after another in this way or, is there another way to do it?

Thanks!

4

There are 4 best solutions below

1
Tyler Durden On

Why dont you use the .each() function to loop through your "widgets".

var map = { 
  'mywidget1': '#mywidget1', 
  'mywidget2': '#mywidget2' 
}; 
$.each(map, function(key, value) {
  $(value).fadeIn(...);
});

or if they all have a something in common (i.e. class of tag combination etc.) this would be even easier.

See .each() jQuery API

4
Carl On

Try this, using jQuery:

    $(document).ready(function(){
        var widgets = $('.widget');
        var fader = function(widget_n){
            if (widget_n < widgets.length) {
                $(widgets.get(widget_n)).fadeIn('slow', function(){
                    fader(widget_n +1);
                });    
            }
        };

        if (widgets.length > 0) {
            fader(0);
        }
    });
0
jdramaix On
0
Manolo Carrasco Moñino On

You are overriding an incorrect method: f(Event) is used for events, change it by f():

$(myWidget1).fadeIn(new Function(){
  public void f() {
     $(myOtherWidget).fadeIn();
  }
});