mouseover和addClass jQuery示例 [英] mouseover and addClass jQuery example

查看:98
本文介绍了mouseover和addClass jQuery示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个导航< 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆