Jquery本身不支持變色,Jquery Color.js彌補了這缺陷並為animate動畫賦予變色效果,如下紅變藍后執行回調再由藍變紅。
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <style> #box { width:100px; height:100px; background-color:red; cursor:pointer; } </style> </head> <body> <div class="box" id="box"></div> <script type="text/javascript" src="/js/jquery-1.8.3.min.js"></script> <script type="text/javascript" src="/js/jquery.color.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#box").mouseenter(function () { $(this).stop(true, true).animate({ "backgroundColor": 'blue' }, 5400, function () { $(this).animate({ "backgroundColor": 'red' }, 5400); }); }); }); </script> </body> </html>
支持的其他屬性如下
backgroundColor, borderBottomColor, borderLeftColor, borderRightColor, borderTopColor, color, columnRuleColor, outlineColor, textDecorationColor, textEmphasisColor