2014-03-19 105 views
0

我正在嘗試爲引導中的懸停縮略圖創建自定義效果。關於如何更有效地編寫此代碼的任何想法?似乎一旦INA而有色格將了slideDown但內自定義jquery動畫效果

JS

$("[rel='tooltip']").tooltip();  

$('.thumbnail').hover(
    function(){ 
      $(this).find('.caption').slideDown(250).animate({"background-color":"rgba(242, 200, 2, 0.75)"},900); 
      $(this).find('.captionhead').show().animate({"color":"black","font-size":"24px"},400,"easeOutBounce"); 
       $(this).find(".captionph").show().animate({"color":"black","font-size":"30px"},400,"easeOutBounce"); 
    }, 
    function(){ 
      $(this).find('.caption').slideUp(250).animate({"background-color":"rgba(66, 139, 202, 0.75)"},600, function(){ 
         $(this).find('.captionhead').animate({"color":"white","font-size":"18px" },100).hide(); 
         $(this).find(".captionph").animate({"color":"black","font-size":"10px"},100,"easeOutBounce").hide(); 
      }); //.fadeOut(205) 

     }  
); 

HTML

<div class="col-sm-6 col-md-3 bpad"> 
     <div class="thumbnail"> 
     <div class="caption"> 
      <h4 class="captionhead">Sliced Bread</h4> 
      <p class="captionph">description</p> 
     </div> 
     <div> 
      <img class="img-circle img-responsive" src="photo/1.jpg" alt="logo"> 
     </div>  
     </div> 
    </div> 
+1

第一關,獲得完全擺脫'(本).find(...'部分,你不需要他們,第二,有關你想要達到什麼的更多信息以及正在發生的事情將不勝感激;) – webeno

+1

沒有必要擺脫$(this).find ..(它在那裏爲'上下文') – Jack

+0

指出!在我的回答中更正,謝謝! – webeno

回答

1

看起來在我身邊好不會顯示標題和pH值的元素,至少按你的描述去:

個HTML

<div class="col-sm-6 col-md-3 bpad"> 
<div class="thumbnail"> 
    <div class="caption"> 
     <h4 class="captionhead">Sliced Bread</h4> 

     <p class="captionph">description</p> 
    </div> 
    <div> 
     <img class="img-circle img-responsive" src="photo/1.jpg" alt="logo" /> 
    </div> 
</div> 
</div> 

JS

$("[rel='tooltip']").tooltip(); 

$('.thumbnail').hover(

function() { 
$(this).find('.caption').slideDown(250).animate({ 
    "background-color": "rgba(242, 200, 2, 0.75)" 
}, 900); 
$(this).find('.captionhead').show().animate({ 
    "color": "black", 
     "font-size": "24px" 
}, 400, "easeOutBounce"); 
$(this).find(".captionph").show().animate({ 
    "color": "black", 
     "font-size": "30px" 
}, 400, "easeOutBounce"); 
}, 

function() { 
$(this).find('.caption').slideUp(250).animate({ 
    "background-color": "rgba(66, 139, 202, 0.75)" 
}, 600, function() { 
    $(this).find('.captionhead').animate({ 
     "color": "white", 
      "font-size": "18px" 
    }, 100).hide(); 
    $(this).find(".captionph").animate({ 
     "color": "black", 
      "font-size": "10px" 
    }, 100, "easeOutBounce").hide(); 
}); //.fadeOut(205) 

}); 

這裏是一個小提琴:http://jsfiddle.net/2d9G7/1/

+1

只需注意:$(this).find不是「不必要的」 - 它給出了選擇器範圍(或上下文)。它不會查詢整個DOM(這是你的小提琴的作用),它會有一個父母。它不僅性能更好,而且避免了與具有相同類名的多個元素的衝突。 – Jack

+1

注意並更正,謝謝! – webeno

+0

感謝webeno,但是當我嘗試你的方式時,p&h4元素偶爾消失。通過我的代碼,h1&p元素將零星地回覆到它們的鼠標狀態 – Vynce82