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