2012-02-11 58 views
0

我div divs中的圖像和段落,當你滾動標題我想段顯示,這段代碼適用於我的其他網站,但由於某種原因心不是在這裏工作我想每個div顯示其內容的按鈕懸停

誰能告訴我什麼,我做錯了

$(document).ready(function() { 

$('.post-band h2').hover(function(){ 
     $(".entry p",this).fadeTo("fast", 1); 
      //$(".entry p",this).slideDown(); 
     }, 
    function(){ 
     $(".entry p",this).fadeTo("fast", 0); 
     // $(".entry p",this).slideUp(); 
       }); 

});

<div class="post-band" id="post-67"> 

<h2>Dale Rodman</h2> 
<div class="band-image"> 
<img width="300" height="250" src="http://localhost/wp-content/uploads/2012/02/dale1.jpg" class="attachment-post-thumbnail wp-post-image" alt="dale" title="dale" /></div> 

<div class="entry"> 
    <p>Dale has been passionate about music ever since he stopped being passionate about something else, when he puts his mind to something there is not stopping this machine, playing guitar since he was little his ability to absorb different styles has help to create a style like non other.</p> 
<h3>Acoustic Guitar, Vocals</h3> 
</div> 
    </div> 
+1

什麼是您的HTML標記? [JS小提琴演示](http://jsfiddle.net/)如何幫助我們來幫助你? – 2012-02-11 17:37:36

+0

雖然,問題可能出現在您的HTML中。你會添加到你的問題嗎?這樣,我們中的一個人可以通過一個有效的代碼示例爲您提供jsfiddle響應。 – Jacksonkr 2012-02-11 17:38:00

+0

你能發佈你的html代碼嗎? – NewUser 2012-02-11 17:51:32

回答

0

$(".entry p",this)在懸停功能查找內部$('.post-band h2')選擇(在h2內)。你可能需要組合.closest()去,然後.find()去。

但張貼您的HTML以獲得更好的答案。

+0

我在上面加了html, – goetzs 2012-02-11 19:11:13

+0

這是我懷疑的。而不是'$(「。entry p」,this)'use'$(this).closest('。post-band')。find('。entry p')' – ori 2012-02-11 20:43:32

0

這裏是一個可能的解決方案小提琴:http://jsfiddle.net/sDJDr/

我使用的JavaScript低於也是什麼ORI以上的意思。

$(document).ready(function() { 

    $('.post-band h2').hover(function(){ 
     var $p = $(this).closest('div.post-band').find('p'); 
     $p.fadeTo("fast", 1); 
     //$(".entry p",this).slideDown(); 
    }, 
    function(){ 
     var $p = $(this).closest('div.post-band').find('p'); 
     $p.fadeTo("fast", 0); 
     // $(".entry p",this).slideUp(); 
    }); 

});