滑鼠移入圖片區塊,標題從上滑入、描述從下滑出;移出則反向滑出隱藏。可搭配 jQuery Easing 增加彈性動畫。
$('.item').hover(
function() { // mouseenter
$(this).children('div.title').stop().animate({top: 0}, 700, 'easeOutBounce');
$(this).children('div.desc').stop().animate({bottom: 0}, 700, 'easeOutBounce');
},
function() { // mouseleave
$(this).children('div.title').stop().animate({top: -60}, 500);
$(this).children('div.desc').stop().animate({bottom: -40}, 400);
}
);
<div class="item">
<img src="photo.jpg" alt="">
<div class="title" style="position:absolute; top:-60px;">標題</div>
<div class="desc" style="position:absolute; bottom:-40px;">描述內容</div>
</div>
.item { position: relative; overflow: hidden; }.stop() 防止動畫排隊疊加