当浏览器滚动到命名锚点时是否会触发事件? [英] Is there an event that fires when a browser scrolls to a named anchor?

查看:86
本文介绍了当浏览器滚动到命名锚点时是否会触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用命名锚链接到页面时,例如page.html#heading将浏览器加载页面,然后跳转到锚点。是否有一个浏览器事件在完成后触发?

When linking to a page using a named anchor e.g. page.html#heading the browser will load the page, then jump down to the anchor. Is there a browser event that fires when this has completed?

解释其背后的原因:我想使用该事件在浏览器中触发动画。

To explain my reasons behind it: I want to use the event to trigger an animation in the browser.

非常感谢。

推荐答案

更改哈希会触发 hashchange 事件

Changing the hash triggers the hashchange event.

但是,我不认为在加载链接已经具有哈希集的网址时会触发它。 如果您希望根据哈希值运行某个脚本,则可以在页面加载时检查哈希值( location.hash )。

However, I don't think it fires when loading a url where the link already has the hash set. But you can check the hash (location.hash) on page load if you want a certain script to run depending on the hash.

这篇关于当浏览器滚动到命名锚点时是否会触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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