滑鼠移入綠色方塊 → 寬高放大 → 微微縮小回彈 → 移出 → 恢復原尺寸。類似果凍般的彈性視覺回饋。
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(function() {
$("div.jelly").hover(
function() { // mouseenter
$(this).stop(true) // 停止當前動畫,清除佇列
.animate({ width: "320px", height: "100px" }, 100)
.animate({ width: "310px", height: "90px" }, 100);
},
function() { // mouseleave
$(this).stop(true)
.animate({ width: "300px", height: "80px" }, 100);
}
);
});
</script>
<style>
.jelly {
width: 300px; height: 80px;
border-radius: 8px; background: #27ae60;
margin-top: 10px;
}
body { background: #e8e8e8; padding: 20px; }
</style>
</head>