【发布时间】:2014-07-14 12:11:04
【问题描述】:
我不明白为什么我的代码不起作用...
我想在单击时为标题的颜色设置动画,但它不起作用。
我将页面缩小到这个简单的部分,因为其余部分不需要动画并且工作正常。
这是JSFiddle
HTML
<head>
<script src="Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="Scripts/Script.js" type="text/javascript"></script>
</head>
<div id="Nav">
<h2>About</h2>
<h2>Works</h2>
<h2>Contacts</h2>
</div>
CSS
#Nav {
position: fixed;
top: 0;
left: 0;
padding: 10px;
z-index: 2;
}
#Nav h2 {
display: table;
color: #353535;
}
#Nav h2:hover {
cursor: pointer;
}
JQUERY
function sortEvents() {
$("#Nav h2").click(function () {
$("h2").animate({ "color": "#f49d29" }, 1500);
})
}
【问题讨论】:
-
单独的 jQuery 无法为颜色设置动画。你需要一个像github.com/jquery/jquery-color这样的插件
标签: jquery animation jquery-animate