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?!?

有帮助吗?

解决方案

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.

其他提示

Try this

<body onLoad='expand();'>

and then put the necessary in a function

<script>
 function expand()
{
$(this).children().next().hide();
   $(this).children().next().slideDown(500);
}
</script>

JQM has its own eventing that you need to hook into. Docs here: http://api.jquerymobile.com/category/events/

If you want to trigger an event on certain pages use this syntax:

$( document ).on( "pageinit", "#some-page", function() {
   ...
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top