sty*_*yke 2 css jquery setinterval jquery-mobile jquery-mobile-loader
我正在构建一个富含图像和交互元素的Web应用程序.出于这些原因,我只想在加载所有图像后显示页面:
$(document).on('pageinit', function(){
$('.ui-content').hide();
var imgs = $(".ui-content img").not(function() { return this.complete; });
var count = imgs.length;
if (count) {
imgs.load(function() {
count--;
if (!count) {
$(".ui-content").show()
}
});
} else {
$(".ui-content").show();
}
});
Run Code Online (Sandbox Code Playgroud)
我需要a)完全移除装载器并用我自己的装置替换它,或者b)使装载机保持运转直到上述功能完成.
如何卸下装载机或在不需要之前保留它?
jQuery Mobile自定义加载器
方案:
工作jsFiddle:http://jsfiddle.net/Gajotres/vdgB5/
Mobileinit必须在jQuery Mobile初始化之前和jQuery之后初始化事件.此外,还必须对css进行一些其他更改才能实现.
首先,我们需要覆盖默认ui-loader-default类,因为它的不透明度很低,最终的微调器很难看到.根据需要改变不透明度值.
.ui-loader-default {
opacity: 1 !important;
}
Run Code Online (Sandbox Code Playgroud)
这是我们的旋转器.
.custom-spinner {
width: 37px !important;
height: 37px !important;
background-image:url('http://pictures.reuters.com/ClientFiles/RTR/Images/ajax-loader.gif');
display: block;
}
Run Code Online (Sandbox Code Playgroud)
这是一个有效的例子:
代码示例
HTML:
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<style>
.ui-loader-default {
opacity: 1 !important;
}
.custom-spinner {
width: 37px !important;
height: 37px !important;
background-image:url('http://pictures.reuters.com/ClientFiles/RTR/Images/ajax-loader.gif');
opacity: 1 !important;
display: block;
}
</style>
<script type="text/javascript" src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js"></script>
<script>
$( document ).bind( 'mobileinit', function(){
$.mobile.loader.prototype.options.text = "loading";
$.mobile.loader.prototype.options.textVisible = false;
$.mobile.loader.prototype.options.theme = "a";
$.mobile.loader.prototype.options.html = "<i class='custom-spinner'></i>";
});
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
$(document).on('pageshow', '#index', function(){
$.mobile.loading( 'show');
});
</script>
</head>
<body>
<div data-role="page" id="index">
<div data-theme="a" data-role="header">
<h3>
First Page
</h3>
<a href="#second" class="ui-btn-right">Next</a>
</div>
<div data-role="content">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
一些浏览器,包括像Chrome这样的webkit浏览器,有一个jQuery mobile ajax loader的程序化执行.它们可以使用serinterval手动执行,如下所示:
$(document).on('pagebeforecreate', '#index', function(){
var interval = setInterval(function(){
$.mobile.loading('show');
clearInterval(interval);
},1);
});
$(document).on('pageshow', '#index', function(){
var interval = setInterval(function(){
$.mobile.loading('hide');
clearInterval(interval);
},1);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9769 次 |
| 最近记录: |