mouseover和addClass jQuery示例 [英] mouseover and addClass jQuery example
问题描述
< ul class =nav>
我想改变。我基本上在寻找 a:hover
效果,只是淡入(我使用精灵,并从一个精灵区域到下一个)。 我在头文件中的代码如下所示:
$(document) .ready(function(){
$(。nav li)。mouseover(function(){
addClass('hovered');
});
}) ;
在我对jQuery的理解中,它说:一旦准备好文档,就可以侦听一个mouseover事件所有 .nav li
元素,当你听到这些时,添加一个悬停的类,所以这就是我想要发生的事情,但现在 - 没有 - 正在发生。
最后我会添加动画和mouseOut,但我希望能够让这部分工作正常,谢谢!
您必须给.addClass一个元素来处理。
$(this).addClass('hovered');
here's a gimme for anyone that knows jQuery:
I have a navigation <ul class="nav">
I want to change around. I'm basically looking for the a:hover
effect, just faded in (I'm using sprites, and going from one sprite area to the next).
The code I have in my header looks like this:
$(document).ready(function(){
$(".nav li").mouseover(function(){
addClass('hovered');
});
});
In my understanding of jQuery, this says "Once the document it ready, listen for a mouseover event on all .nav li
elements. When you hear that, add a class "hovered" to it. So that's what I want to have happen, but right now -nothing- is happening.
Eventually I'll add in the animation and mouseOut, but I'd like to be able to get this part working as I want it. Thanks!
You have to give .addClass an element to work with.
$(this).addClass('hovered');
这篇关于mouseover和addClass jQuery示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!