作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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>
提前致谢
最佳答案
只需定义一个事件,在 mouseenter
和 mouseleave
上添加或删除类。
$$('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/
我是一名优秀的程序员,十分优秀!