继续甚至同时改变页面的音乐播放 [英] Continuing music playback even while changing pages

查看:146
本文介绍了继续甚至同时改变页面的音乐播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的SoundCloud 是一个了不起的网站,利用HTML5和Backbone.js的的。唯一的一点是,我无法找到他们所使用的技术,让音乐继续玩,甚至同时改变页面。

SoundCloud is an amazing site that makes use of HTML5 and Backbone.js. The only thing is, I can't find what technology they use that allows the music to keep playing even while changing pages.

如何能找出他们是如何做到的?

How can one find out how they did it?

推荐答案


事实是,你不加载一个新的页面,但内容是通过AJAX加载。

The fact is, that you do not load a new page, but the content is loaded via AJAX.

页上,然后使用HTML5历史API添加的可能性使用浏览器的后退和前进按钮来浏览。

The page then uses the HTML5 History API to add the possibility to Navigate using the browser's backward and forward buttons.

我开始进入这一主题通过阅读和尝试以下两种资源:

I started into this topic by reading and trying out the following two resources:

http://diveintohtml5.info/history.html 结果
http://html5demos.com/history

最简单的办法就是装载和替换通过AJAX当前的内容,然后调用

The most simple way is to load and replace the current content via AJAX and then call

history.pushState(null, null, link.href);

为了增加当前显示的页面的历史记录条目。

In order to add the history entry of the currently shown page.

如果你现在preSS后退按钮,浏览器将不会加载previous页,但触发事件 popState 。这可以用来恢复使用AJAX或储存的信息在你的JavaScript变量previous页。

If you now press the back button, the browser won't load the previous page, but fire the event popState. This can be used to restore the previous page using AJAX or information stored in your JavaScript variables.

window.addEventListener("popstate", function(e) {
    //loadPreviousPage();
}

这篇关于继续甚至同时改变页面的音乐播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆