AJAX 是否通过 URL 中的哈希标签调用页面加载?
我正在使用同位素,这是 jsfiddle: http://jsfiddle.net/desandro/DA3wF/
或者,或者,我设置的演示: http://nerdi.net/isotope-test.html
有一个选项 filter: 选择器
我如何传递过滤器,例如: index.html html#green
在页面加载时会过滤到 .green
类吗?这可能吗?
I am using isotope, here's the jsfiddle: http://jsfiddle.net/desandro/DA3wF/
Or, alternatively, a demo I have set up: http://nerdi.net/isotope-test.html
There's an option filter: selector
How could I pass a filter, ex: index.html#green
that on page load, would filter to the .green
class? is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个
if/then
语句,用于检查当前哈希是否为空字符串。如果是,则filter
将设置为default
,否则将设置为window.location.hash
值(减去#
)。像这样的 URL,
index.html
,将导致filter
设置为default
以及像这样的 URL,index.html #my-selector
,将导致filter
设置为.my-selector
。更新
您的代码不起作用的原因实际上与我的代码没有任何关系,但这是我在您的网站上测试的代码的更新版本:
This is an
if/then
statement that checks to see if the current hash is an empty string. If it is thenfilter
will be set todefault
otherwise it will be set to thewindow.location.hash
value (minus the#
).A URL like this,
index.html
, will result infilter
being set todefault
and a URL like this,index.html#my-selector
, will result infilter
being set to.my-selector
.Update
The reason your code isn't working doesn't actually have anything to do with my code, but here is an updated version of your code that I tested on your site:
location.hash将返回“#green”,我们只需将其替换为点即可得到“.green”。
jsfiddle 包含如何根据哈希更改所选链接的示例。
The location.hash will return "#green", we just replace it with a dot to get ".green".
jsfiddle with example of how to also change the selected link based on the hash.