我有我的懸停工作 - 但我有興趣試圖使它更有效,因爲它似乎'滯後',當它發現。 overlay
div。我也遇到過這樣的問題,我在網頁上爲所有.overlay
div製作了動畫,我認爲這是一個不小的錯誤。jQuery懸停動畫效率
無論如何,讓我們學習如何讓以下更好!
jQuery的:
// get aside feature
var aside_feature = $('aside .feature');
// on hover, fade it in
$(aside_feature).hover(function() {
// get the overlay div
var feature_overlay = $(this).find('.overlay');
$(feature_overlay).stop().fadeIn();
// on hover out, fade it out
}, function() {
$(this).find('.overlay').stop().fadeOut();
});
標記:
<aside>
<div class="feature">
<div class="overlay">
<a href="">button</a>
</div><!-- overlay -->
<div class="text">
<p>text</p>
</div><!-- .text-->
<div class="image">
<figure>
<img src="" alt="">
</figure>
</div><!-- .image -->
</div><!-- .feature -->
</aside><!-- aside -->
小提琴:http://jsfiddle.net/9xRML/5/
編輯 - 終極密碼
謝謝@Shomz和@Afro。
最終代碼選擇是使用tranisitons,並配上Modernizr的detection for transitions,我改變了我的藏疊加的div opacity: 0; *display:none;
和JavaScript作爲後備:
CSS
.overlay {
*display: none;
opacity: 0;
transition: 0.4s all linear;
}
.overlay:hover {
opacity: 1;
}
jQuery的
$(function() {
/*=====================================
= Feature overlay =
=====================================*/
if (!Modernizr.csstransitions) {
// get aside feature
var aside_feature = $('aside .feature');
// on hover, fade it in
$(aside_feature).hover(function() {
$(this).find('.overlay').stop(true, true).fadeIn();
// on hover out, fade it out
}, function() {
$(this).find('.overlay').stop(true, true).fadeOut();
});
}
});
而且你想讓所有enimovali一次?或者你需要什麼? – Pesulap
enimovali是什麼意思,對不起? – SMacFadyen
sry animate .... – Pesulap