2014-08-27 126 views
0

我需要更改懸停在不同類的CSS。以下是密碼Jquery:懸停功能

<li class="dropdown whitedrop" id="dropdown" style="width: 229px;"> 
    <div class="greenStripe"></div> <a data-target="#" style="cursor: Default;margin-left: 50px;width: 180px;" class="fnd-nav-link" data-toggle="dropdown"><span id="loggedon_lable">Logged on:</span> 
     <span id="loggedon_user"></span><b class="caret"></b></a> 
    <ul id="whitedropdown-menu" class="whitedropdown-menu fnd-tweak-dropdown" style=""> 
     <li class="borderli disabledMenu"> <a tabindex="-1" style="cursor: default">My Profile</a> 
     </li> 
     <li class="borderli disabledMenu"> <a tabindex="-1" style="cursor: default">Settings</a> 
     </li> 
    </ul> 
</li> 

在懸停時,'whitedropdown-menu'我需要更改'greenStripe'的背景。

我試過,

.whitedropdown-menu:hover .greenStripe { 
    background:#029f1c; 
} 

它沒有工作actually.But我需要它在jQuery中沒有CSS。 對於我試過,

$(".whitedropdown-menu").hover(function() { 
    $(".greenStripe").css('background', '#029f1c'); 
}); 

但一旦我懸停,背景的變化,當我不徘徊它沒有得到回覆。

請幫忙, 謝謝。

+0

。 – 2014-08-27 13:25:18

回答

1
$(".whitedropdown-menu").hover(function(){ 
    // Function called when hover 
    // Go from background1 to background2 

}, function() { 
    // Function called when hover end 
    // Go from background2 to background1 
}); 

.hover()

0

嘗試鼠標移出代碼:

$(".whitedropdown-menu").mouseout(function() { 
    $(".greenStripe").css('background','#029f1c'); //change this color to the color you want 
    }); 
0

請與下面的代碼片段嘗試。

$(".whitedropdown-menu").mouseout(function() { 
    $(".greenStripe").css('background','#029f1c'); 
}); 

您必須再添加一個jquery事件來處理這個事件。 OnMouseOut你必須再次改變背景。

0

一次嘗試將鼠標光標離開你的容器移動樣式:

$('.whitedropdown-menu').mouseout(function() { 
    $('.greenStripe').css('background','none'); //replace the none with the initial background color 
}); 
你必須告訴它手動刪除樣式