2014-02-19 443 views
0

如何在鼠標懸停目標對象時顯示和隱藏對象p?如何在鼠標懸停上顯示/隱藏元素?

jQuery代碼:

$('.jcarousel-item-horizontal').hover(function(event){ 
        event.preventDefault(); 
        event.stopPropagation(); 
        $("p[class*='hover_carosuel']").fadeIn(300) 
        },function(){ 
        $("p[class*='hover_carosuel']").fadeOut(400) 
       }) 

示例代碼HTML:

<li class="odd jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal" jcarouselindex="1" style="float: left; list-style: none;"> 
    <div class="views-field views-field-field-zdjecie"> 
     <div class="field-content"> 
      <a href="http://www.localhost/linia-pro"><img typeof="foaf:Image" src="http://www.localhost/sites/default/files/pro.png" width="90" height="90" alt=""></a> 
     </div> 
    </div> 
    <div> 
     <p class="hover_carosuel"> 
      <a href="/linies">Pro</a> 
     </p> 
    </div> 
</li> 

<li class="odd jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal" jcarouselindex="1" style="float: left; list-style: none;"> 
    <div class="views-field views-field-field-zdjecie"> 
     <div class="field-content"> 
      <a href="http://www.localhost/linia-pro"><img typeof="foaf:Image" src="http://www.localhost/sites/default/files/pro.png" width="90" height="90" alt=""></a> 
     </div> 
    </div> 
    <div> 
     <p class="hover_carosuel"> 
      <a href="/linies">Pro</a> 
     </p> 
    </div> 
</li> 

<li class="odd jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal" jcarouselindex="1" style="float: left; list-style: none;"> 
    <div class="views-field views-field-field-zdjecie"> 
     <div class="field-content"> 
      <a href="http://www.localhost/linia-pro"><img typeof="foaf:Image" src="http://www.localhost/sites/default/files/pro.png" width="90" height="90" alt=""></a> 
     </div> 
    </div> 
    <div> 
     <p class="hover_carosuel"> 
      <a href="/linies">Pro</a> 
     </p> 
    </div> 
</li> 
+1

*** 「如何jqeury」 我***沒有意識到jQuery也可以用作動詞:P。你能給我們提供一個jsfiddle嗎? http://jsfiddle.net/ – RononDex

+0

如果我沒有弄錯這個:http://jsfiddle.net/Z9xDK/是你所追求的。否則,請提供更多詳情。 – eithed

回答

1

試試這個,

$(function(){ 
    $('.jcarousel-item-horizontal').hover(function(event){ 
     event.stopPropagation(); 
     $(this).find("p.hover_carosuel").fadeIn(300); // fade-in only the child p element 
    },function(){ 
     $(this).find("p.hover_carosuel").fadeOut(400);// fade-out only the child p element 
    }); 
}); 
相關問題