如何创建动画加载指示器 Spotify 应用程序

发布于 2024-12-23 02:14:46 字数 60 浏览 2 评论 0原文

如何使用设计资源文件夹中提供的loading_indicator.png 使其像ajax 加载器一样工作?

How I do use the loading_indicator.png provided in the design resources folder to make it act like an ajax loader?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

濫情▎り 2024-12-30 02:14:46

这就是我在启动应用程序时显示加载指示器的方式,该指示器取自“主页”应用程序(新增功能)。在你的index.html 中:

<div class="loading">
  <div class="throbber"><div></div></div>
</div>

在你的app.css 中:

@import url("sp://import/css/eve.css");

adam.css 是深色Spotify 主题,eve.css 是浅色主题。然后,当您的应用程序加载完成后,只需删除该元素即可。您可以使用 spotify dom.js 中的 dom 方法来完成此操作。在你的app.js中:

var dom = sp.require('sp://import/scripts/dom');

var loadingEl = dom.queryOne('.loading');
dom.destroy(loadingEl);

我不知道dom.js是否会出现在官方API中。否则,您可以通过任何其他方式删除它(标准 dom 方法、您正在使用的其他 js 库等):

var loadingEl = document.querySelector('.loading');
loadingEl.parentNode.removeChild(loadingEl);

请注意,上面的示例不一定使用loading_indicator.png,而是使用 adam.css 和 eve 使用的任何图像.css 主题。

如果您不想将加载程序用作应用程序内的普通 Ajax 加载指示器,则适用 Web 应用程序的所有正常规则。启动ajax调用时显示加载器,将其隐藏在completed-callback中,使用css定位。

This is how I display a loading indicator when starting my app, taken from the 'home' application (What's New). In your index.html:

<div class="loading">
  <div class="throbber"><div></div></div>
</div>

In you app.css:

@import url("sp://import/css/eve.css");

adam.css being the dark Spotify theme and eve.css the light. Then, when your application is finished loading, just remove the element. You can do it with the dom methods in the spotify dom.js. In your app.js:

var dom = sp.require('sp://import/scripts/dom');

var loadingEl = dom.queryOne('.loading');
dom.destroy(loadingEl);

I don't know if the dom.js will be in the official API or not. Otherwise you can remove it any other way (standard dom methods, other js libraries you're using, etc):

var loadingEl = document.querySelector('.loading');
loadingEl.parentNode.removeChild(loadingEl);

Note that the above example does not necessarily use the loading_indicator.png but whatever images that are used by the adam.css and eve.css themes.

If you wan't to use the loader as a normal ajax loading indicator inside your app, then all the normal rules of web apps apply. Display loader when initiating ajax call, hide it in completed-callback, position it with css.

怪我入戏太深 2024-12-30 02:14:46

我意识到这是一个老话题,但是使用 1.X API,有一种更简单的方法可以通过 使用 Throbber 类,它允许您通过 JS 相当简单地实例化和隐藏。

var tracks = document.getElementById('tracks');
var throbber = Throbber.forElement(tracks);
// (wait for tracks to load and render)
throbber.hide();

只需确保在 JS 的开头包含 Throbber 类即可:

require([
  '$views/throbber#Throbber'
], function (Throbber) {

I realize this is an old topic, but with the 1.X API there is an easier way to do this by using the Throbber class which allows you to instantiate and hide fairly simply via JS.

var tracks = document.getElementById('tracks');
var throbber = Throbber.forElement(tracks);
// (wait for tracks to load and render)
throbber.hide();

Just make sure to include the Throbber class at the beginning of your JS:

require([
  '$views/throbber#Throbber'
], function (Throbber) {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文