jquery mobile ajax navigation,how to show loader in non ajax navigation in jquery mobile?

夏兴平
2023-12-01

I don't think that a spinner with ajax disabled is possible. I mean you could flash it for a second before or after the page is loaded but that kinda defeats the purpose. I do however know that loading and running specific script on specific pages is possible. So maybe your question should be how do I get specific scripts to run in specific JQM pages?

Binding to pageinit will help you execute your own javascript for specific pages. The following will only execute when a JQM page with the id of page2 is loaded. Just put this in an external script and link to it in the head of your pages.

$(document).on('pageinit','#page2',function(){

$('#appendMe').append('This text was appended');

});

If you want to load an external script/library use the $.getScript(); method. In my example I am going to load and execute the spin.js library when a JQM page with the id of page3 is loaded. Spin.js just puts a little spinner in the page.

​​$(document).on('pageinit','#page3',function(){

$.getScript('http://fgnass.github.com/spin.js/dist/spin.min.js', function(){

//the following code gets executed after spin.js is loaded

var opts = {

lines: 13, // The number of lines to draw

length: 7, // The length of each line

width: 4, // The line thickness

radius: 10, // The radius of the inner circle

rotate: 0, // The rotation offset

color: '#000', // #rgb or #rrggbb

speed: 1, // Rounds per second

trail: 60, // Afterglow percentage

shadow: false, // Whether to render a shadow

hwaccel: false, // Whether to use hardware acceleration

className: 'spinner', // The CSS class to assign to the spinner

zIndex: 2e9, // The z-index (defaults to 2000000000)

top: 'auto', // Top position relative to parent in px

left: 'auto' // Left position relative to parent in px

};

var target = document.getElementById('spin');

var spinner = new Spinner(opts).spin(target);

});

});​​​​​​​​​​​​​​​​

Here is a jsfiddle to convince you I'm not just making this all up. Hehe

 类似资料:

相关阅读

相关文章

相关问答