if(!$().is(":animated"))
{
//如果元素不處於動畫狀態,則新增新的動畫
}
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> figure { position:relative; /*設定相對定位屬性,以便定位子元素*/ width:240px; height:200px; overflow: hidden; } img { width:240px; height:200px; } figcaption { position:absolute; left:0; bottom:-30px; width:100%; height:30px; line-height:30px; text-align:center; font-family:"微軟雅黑"; background-color:rgba(0,0,0,0.6); color:white; } </style> <script src="js/jquery-1.12.4.min.js"></script> <script> $(function () { $("figure").hover(function () { if (!$(">figcaption", this).is(":animated")) { $(">figcaption", this).animate({ "bottom": "0px" }, 200); } }, function () { if (!$(">figcaption", this).is(":animated")) { $(">figcaption", this).animate({ "bottom": "-30px" }, 200); } }) }) </script> </head> <body> <figure> <img src="img/ciri.png" alt=""> <figcaption> 《巫師3》之希里</figcaption> </figure> </body> </html>預設情況下,預覽效果如圖 1 所示。