gpt4 book ai didi

javascript - 如何更改jquery mobile中的默认加载ajax加载器gif

转载 作者:行者123 更新时间:2023-11-28 13:48:50 24 4
gpt4 key购买 nike

我已经看过 jquery mobile 的文档,但无法理解如何将其集成到我的移动网站上。文档位于

http://jquerymobile.com/demos/1.2.0-pre/docs/pages/loader.html

实际上,gif 图像在 2.x android 设备上不会有动画效果,因此我正在考虑制作一种仅文本的预加载小部件。

我尝试像这样通过 css 更改它

.ui-icon-loading {
background: url(themes/images/custom-ajax-loader.gif);
}

但是新图像无法正确缩放,旧背景仍然可见。

我对 javascript 完全是菜鸟。有人可以帮助我吗?

最佳答案

您提到了 jQM 1.2 Alpha 文档,因此我的答案基于此 jQM 版本。

下面您可以找到 2 个更改默认加载程序图像的选项。

解决方案1

如 jQM 1.2 Alpha 文档中所述:

When jQuery Mobile starts, it triggers a mobileinit event on the document object. To override default settings, bind to mobileinit. Because the mobileinit event is triggered immediately, you'll need to bind your event handler before jQuery Mobile is loaded. Link to your JavaScript files in the following order:

<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>

要全局配置加载对话框,可以在 mobileinit 事件期间在其原型(prototype)上定义以下设置:

$( 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 = "";
});

下面您可以找到一个工作示例,您可以在html原型(prototype)选项中完全自定义加载程序。

示例:

<!DOCTYPE html> 
<html>
<head>
<title>Page Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(document).bind( 'mobileinit', function(){
$.mobile.loader.prototype.options.text = "loading";
$.mobile.loader.prototype.options.textVisible = true;
$.mobile.loader.prototype.options.theme = "a";
$.mobile.loader.prototype.options.textonly = false;
$.mobile.loader.prototype.options.html = "<span class='ui-bar ui-overlay-c ui-corner-all'><img src='../images/my-custom-image.png' /><h2>loading</h2></span>";
});
</script>
<script src="http://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.js"></script>
<script>
$(document).on("click", ".show-page-loading-msg", function() {
$.mobile.loading('show');
});
</script>
</head>

<body>
<!-- /page -->
<div data-role="page" class="page-map" style="width:100%; height:100%;">
<!-- /header -->
<div data-role="header" data-theme="b">
<h1>Test</h1>
</div>
<!-- /content -->
<div data-role="content" class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;">
<button class="show-page-loading-msg">Click</button>
</div>
</div>
</body>
</html>

解决方案2

覆盖用于描述页面加载器的默认 CSS 样式。

已编辑

对于jQM 1.1.1 version有以下可配置选项:

  • loadingMessage string, default: "loading"
    Set the text that appears when a page is loading. If set to false, the message will not appear at all.
  • loadingMessageTextVisible boolean, default: false
    Whether the text should be visible when a loading message is shown. The text is always visible for loading errors.
  • loadingMessageTheme string, default: "a"
    The theme that the loading message box uses when text is visible.

代码示例:

<!DOCTYPE html> 
<html>
<head>
<title>Page Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(document).bind( 'mobileinit', function(){
$.mobile.loadingMessageTheme = 'e';
$.mobile.loadingMessageTextVisible = true;
$.mobile.loadingMessage = "test";
});
</script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<script>
$(document).on("click", ".show-page-loading-msg", function() {
$.mobile.showPageLoadingMsg();
});
</script>
</head>

<body>
<!-- /page -->
<div data-role="page" class="page-map" style="width:100%; height:100%;">
<!-- /header -->
<div data-role="header" data-theme="b">
<h1>Test</h1>
</div>
<!-- /content -->
<div data-role="content" class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;">
<button class="show-page-loading-msg">Click</button>
</div>
</div>
</body>
</html>

此外,您可以尝试覆盖用于设置 jQM 加载程序样式的默认 CSS。更具体地说,您可以修改或覆盖加载屏幕部分中的样式以及加载图标部分中用于描述页面加载器的样式。

您会发现here jQM 1.1.1 中使用的 CSS。

/* loading icon */
.ui-icon-loading {
background: url(images/ajax-loader.gif);
background-size: 46px 46px;
}

/* loading screen */
.ui-loading .ui-loader { display: block; }
.ui-loader { display: none; z-index: 9999999; position: fixed; top: 50%; left: 50%; border:0; }
.ui-loader-default { background: none; opacity: .18; width: 46px; height: 46px; margin-left: -23px; margin-top: -23px; }
.ui-loader-verbose { width: 200px; opacity: .88; box-shadow: 0 1px 1px -1px #fff; height: auto; margin-left: -110px; margin-top: -43px; padding: 10px; }
.ui-loader-default h1 { font-size: 0; width: 0; height: 0; overflow: hidden; }
.ui-loader-verbose h1 { font-size: 16px; margin: 0; text-align: center; }
.ui-loader .ui-icon { background-color: #000; display: block; margin: 0; width: 44px; height: 44px; padding: 1px; -webkit-border-radius: 36px; -moz-border-radius: 36px; border-radius: 36px; }
.ui-loader-verbose .ui-icon { margin: 0 auto 10px; opacity: .75; }
.ui-loader-textonly { padding: 15px; margin-left: -115px; }
.ui-loader-textonly .ui-icon { display: none; }
.ui-loader-fakefix { position: absolute; }

关于javascript - 如何更改jquery mobile中的默认加载ajax加载器gif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12225126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com