CSS屬性我有幾個圖片:條件變化(如果/那麼)基於jQuery中
<img class="photo" src="{{ img.url_small }} />
<img class="photo" src="{{ img.url_small }} />
<img class="photo" src="{{ img.url_small }} />
我想,當用戶將鼠標懸停在其上的圖像或點擊更改邊框顏色:
$(".photo").click(function() {
$(".photo").css({"background":"white"});
$(this).css({"background":"blue"});
});
$(".photo").mouseenter(function() {
$(this).css({"background":"green"});
}).mouseleave(function() {
$(this).css({"background":"white"});
});
(有各圖像從而,在背景中的變化改變了邊界周圍白色餘量)
麻煩的是當圖像上的用戶點擊,它變成藍色,但隨後當鼠標從...移開圖像,邊框變成白色。
我嘗試了一些條件語句:
$(".photo").mouseenter(function() {
if($(this).css("background") != "blue") {
$(this).css({"background":"green"});
}
}).mouseleave(function() {
if($(this).css("background") != "blue") {
$(this).css({"background":"white"});
}
});
,但仍從藍色變成白色背部的邊界。我怎樣才能讓邊框保持藍色?有沒有更有效的方法來做到這一點?
嘗試從圖像被點擊時,它刪除鼠標事件處理程序。 – akonsu 2010-10-20 02:09:19