Search code examples
jqueryhtmljquery-mobilejquery-mobile-collapsible

JQuery Mobile event on Page Load


i'm using this code to animate a collapsible content in a html5+jquryMobile app...i add it to my head:

$(document).on('expand', '.ui-collapsible', function() {
   $(this).children().next().hide();
   $(this).children().next().slideDown(500);
})

$(document).on('collapse', '.ui-collapsible', function() {
   $(this).children().next().slideUp(500);
});

it works fine when i click on the collapsible head...i'd like to use it for all my collapsible elements but in some pages i'd like to have the animation automatically after the page is loaded... some one can help me?!?


Solution

  • Working example: http://jsfiddle.net/Gajotres/vmZyn/

    $(document).on('pageshow', '#index', function(){       
        $('.ui-collapsible').children().next().hide();
        $('.ui-collapsible').children().next().slideDown(1500);
    });
    

    You want to use a pageshow event. At that point page you can animate sliding.

    In case you want to do it only one (like document ready) use this syntax instead:

    $(document).on('pageinit', '#index', function(){       
        $('.ui-collapsible').children().next().hide();
        $('.ui-collapsible').children().next().slideDown(1500);
    });
    

    Unlike pageshow, pageinit will trigger only once.