2014-07-22 18 views
0

我想添加不透明度到包含錨標記,圖像,標題(跨度)的div。使用不在jquery

在標題我想表明我的標題是這樣做的所有的div模糊......徘徊 所以我用了不喜歡這個

$(this).not('.Caption').css('opacity', '0.4'); 

我的身體就像

<div> 
    <a href="#"><img src=""/></a> 
    <span class='Caption'>caption</span>  
</div> 

見我的小提琴更好理解.. FiDDle

更新:其實我試圖實現像最後一個演示中Plugin,最後,我結束了像上面

+0

'$(本).find( ':不是(.Caption)')。CSS( '不透明', '0.4');' – Satpal

+0

@Satpal - 你肯定這是一個有效的編輯?也許OP沒有真正的span元素的class屬性... – Lix

+1

@Lix,是的,這是有效的編輯,OP提供了小提琴。它在那裏提到。 – Satpal

回答

1

你的意思是這樣的? =>http://jsfiddle.net/ggLG8/6/

$('.thumbnail').hover(function() { 
     $(this).children().not('.Caption').css('opacity', '0.4'); 
},function(){ 
    $(this).children().not('.Caption').css('opacity', '1'); 
}); 

也必須刪除從.thumbnail:hoveropacity:0.4;在CSS

+0

這沒有做任何事情。 –

+0

@TimBJames檢查小提琴,'.Caption'不透明度不變,但其餘的! –

+0

@Amin請參閱http://jsfiddle.net/ggLG8/8/ .. – user3860465

0

小提琴可以使用:

$(this).find('*').not('.Caption').css('opacity', '0.4'); 

這將不透明度設置爲除了一個與Caption類的所有子元素。

0

這happend因爲 「.caption」 元素是你的 「格」 內
試試這個:

<div class="someclass"> 
<div class="thumbnail" > 
<a class="fancybox" href="http://demo.phpgang.com/crop-images/demo_files/pool.jpg" rel="group1"> 
    <img width="150" height="120" src="http://demo.phpgang.com/crop-images/demo_files/pool.jpg"/> 
</a> 
    </div> 
    <span class='Caption' contenteditable='true'>Caption</span> 
</div> 
0

問題不在於你的jQuery,而是因爲你將不透明度應用於包含其他元素的元素。當你這樣做時,包含元素中的所有元素都會繼承不透明性。

最簡單的解決方案是去除不透明度並更改.thumbnail元素的背景顏色,並從CSS樣式中去除不透明度。

$('.thumbnail').hover(function() { 
     $(this).not('.Caption').css('background-color', 'rgba(249, 160, 160, 0.4)'); 
     $(this).find('.Caption').animate({ 
      opacity: 'show', 
      bottom: 0 
     }, 'fast');  
}); 

看到這個updated fiddle

+0

你認爲你使用'不'...但德M8 B使用它的問題...我是對的.. – user3860465