gpt4 book ai didi

mootools - 如何在 MooTools 中的悬停元素上添加类?

转载 作者:行者123 更新时间:2023-12-01 07:29:48 24 4
gpt4 key购买 nike

我正在使用 MooTools 1.12

如何在悬停时将类添加到 a 元素?

例如

我有这个

<a href="example.html">Some text</a>
<a href="example.html">Some text</a>
<a href="example.html">Some text</a>
<a href="example.html">Some text</a>

anf 当鼠标悬停在链接上时我想要这个:

<a href="example.html">Some text</a>
<a href="example.html">Some text</a>
<a class="hover" href="example.html">Some text</a> <!-- I am over this link -->
<a href="example.html">Some text</a>

提前致谢

最佳答案

只需定义一个事件,在 mouseentermouseleave 上添加或删除类。

$$('a').addEvents({
'mouseenter': function() { $(this).addClass('hover'); },
'mouseleave': function() { $(this).removeClass('hover'); }
});

但是,如果您使用它来更改链接上的 CSS 属性,则最好在 CSS 中使用 :hover 伪类。使用伪类将使您的更改能够在没有 Javascript 的浏览器上运行。

关于mootools - 如何在 MooTools 中的悬停元素上添加类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7041271/

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