是否有可能有网址的变化,而你向下滚动单页 [英] Is it possible to have the url change while you scroll down a single page

查看:133
本文介绍了是否有可能有网址的变化,而你向下滚动单页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能有网址的变化,而你向下滚动单页使用Ajax?我有一个网站都在一个页面上,并希望有这样的效果。

Is it possible to have the url change while you scroll down a single page with ajax? I have a website all on one page and want to have this effect.

例如:

www.blablabla.com/blog

用户向下滚动...

user scroll down...

www.blablabla.com/blog/entry-name

我知道散列......我可以屏蔽网址?

I know about hashing... can I mask the URL?

推荐答案

我知道这是一个有点一个老问题,但浏览器改变了,而现在,可以做海报要求。这意味着,其他大多数答案都不再有效。我张贴的方式来做到这一点,以便它可以使用谷歌找到正确的答案帮助的人。

I know this is a bit of an older question, but browsers changed, and right now, it is possible to do what the poster requested. This means that most of the other answers are no longer valid. I'm posting a way to accomplish this so that it might help people using Google to find the correct answer.

总之,在现代浏览器(浏览器与HTML 5的支持),您可以。请看看这个的文章。

In short, on modern browsers (browsers with HTML 5 support) you can. Please have a look at this article.

这基本上可以归结为以下行code:

It basically boils down to the following line of code:

window.history.pushState("object or string", "Title", "/new-url");

执行上面的code将更改URL,以example.com/new-url~~V,并会帮助你完成你想要的。

Executing the above code will change the URL to example.com/new-url, and will help you accomplish what you wanted.

有关演示,你可以看看在威比奖,其中该方法被使用。只需向上或向下滚动,并期待在地址光秃秃的。其效果是pretty的IM pressive。

For a demo, you can take a look at the Webby Awards, where this method is used. Just scroll up or down and look at the address bare. The effect is pretty impressive.

这篇关于是否有可能有网址的变化,而你向下滚动单页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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