如何在dom中进行一次持续的更改

How to make a change in the dom that lasts for one click

我正在构建一个网页,我已经设置了一个正文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