2014-02-15 18 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

相關問題