gpt4 book ai didi

javascript - 如何在持续单击一次的dom中进行更改

转载 作者:太空宇宙 更新时间:2023-11-04 02:17:25 25 4
gpt4 key购买 nike

我正在构建一个网页,我已经设置了一个正文 backround-image。有没有办法在用户按下鼠标键时更改图像的 url,并在释放鼠标键时将其更改回来?基本上,更改持续的时间与点击本身的时间相同。

此外,我如何确保此更改对页面上任意位置的点击有效?将事件监听器添加到 body 元素就足够了吗?提前致谢。

最佳答案

The :active pseudo-class applies while an element is being activated by the user. For example, between the times the user presses the mouse button and releases it. On systems with more than one mouse button, :active applies only to the primary or primary activation button (typically the "left" mouse button), and any aliases thereof.

css3-selectors spec


纯 CSS 示例:

body:active {
background-image: [IMAGE];
}

Example jsfiddle

关于javascript - 如何在持续单击一次的dom中进行更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38676590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com