2011-03-01 61 views
0

简单问题的道歉我刚刚开始。 我有一个导航div和4个按钮类div。在div中选择一个div

我希望能够改变背景类的相应按钮DIV当鼠标悬停/输入等

这是我的Jquery到目前为止

<script> 
$(document).ready(function(){ 
    $("#nav").mouseenter(function(){ 
    $(this).stop(true,true).find(".button").fadeTo(200,0.5,function(){ 
    $("#nav").mouseleave(function(){ 
    $(this).stop(true,true).find(".button").fadeTo(200,1); 
    }); 
    }); 
    }); 
}); 
</script> 
+1

问题是什么?你有什么问题? – Ikke 2011-03-01 11:56:20

+1

在jsfiddle.com上设置你的代码,发布链接,我们可以建议一个更好的方法来做到这一点 – Jason 2011-03-01 11:59:04

+0

我的主要问题是在div中选择一个div,然后在mouseEnter时淡入该选定div的css属性。 – George 2011-03-01 12:17:27

回答

1

我想你可能希望这样的:

<script> 
$(document).ready(function(){ 
    $("#nav .button").mouseenter(function(){ 
    $(this).stop(true,true).fadeTo(200,0.5,function(){ 
    $(this).mouseleave(function(){ 
    $(this).stop(true,true).fadeTo(200,1); 
    }); 
    }); 
    }); 
}); 
</script> 

我不知道这是什么一样,也做了测试,但问题是我想你想的事件处理程序添加到按钮本身,而不是容器。是这样吗?

+0

谢谢Victor给了我想要的效果。 .mouseenter字符串显示了我从现在开始如何操作。 – George 2011-03-01 12:16:22

0

试试这个:

$('#nav').find('.button').each(function(){ 
    $(this).mouseover(function(){ 
     $(this).attr('style', 'background:url(http://jsfiddle.net/favicon.gif) top left'); 
    }); 
    $(this).mouseout(function(){ 
     $(this).attr('style', 'background:none'); 
    }); 
}); 

你可以看到它在这里工作 - http://jsfiddle.net/FDQXa/

+0

嗨亚历克斯你可以使背景Gif淡入?我的主要问题是选择divs内的div – George 2011-03-01 12:13:55