2014-02-15 19 views
1

我想当我悬停'.post'div时,'.post'div的其余部分发生变化,例如其背景。当鼠标悬停一个div时,其余部分发生变化

我该怎么做?

CSS:

.post { width: 25px; height: 25px; } 

HTML:

<div class="post"> ... </div> 
<div class="post"> ... </div> 
<div class="post"> ... </div> 
<div class="post"> ... </div> 

回答

2

使用悬停功能和.not(this)

$('.post').hover(function() { 
    // .css can be anything you want it to be 
    $('.post').not(this).css({'color':'red'}); 
}, function() { // Revert back to default (optional) 
    $('.post').css({'color':'black'}); 
}); 

Demo

+0

完美,谢谢! – user3052619

1

使用jQuery:

$(function(){ 
    $("div.post").mouseover(function(){ 
    $(this).siblings().css("background-color","red"); 
}); 
$("div.post").mouseout(function(){ 
    $(this).siblings().css("background-color","white"); 
}); 
}); 
+0

我想你不小心张贴了一个断开的链接。 – Anonymous

+0

没有它的正确链接只有你可以看到那里的答案演示 – user3313598

+0

它现在似乎有点工作,但它只是进入登录屏幕。使用[JSFiddle](http://jsfiddle.net)要好得多。 – Anonymous

相关问题