我对jQuery很新,我真的无法理解这一点。
我正在尝试选择<a href="contact"><div id="res">Reserveren</div></a>
。
这是我的jQuery代码:
$(document).ready(function() {
$('#res').hover(
function () {
$(this).animate({backgroundColor: "#fff" });
},
function () {
$(this).animate({backgroundColor: "#000" });
}
});
然而,没有任何工作。它根本没有改变任何东西......我做错了什么?
提前致谢, 巴特
答案 0 :(得分:7)
jQuery不会,无法,不使用a suitable plug-in或jQuery UI library动画color
。
但是,您可以使用类名来利用CSS转换:
$('#res').hover(
function () {
$(this).addClass('animating');
},
function () {
$(this).removeClass('animating');
});
使用以下CSS:
#res { /* default styles */
background-color: #000;
-moz-transition: background-color 1s linear;
-ms-transition: background-color 1s linear;
-o-transition: background-color 1s linear;
-webkit-transition: background-color 1s linear;
transition: background-color 1s linear;
}
#res.animating, /* hovered-class/animating styles */
.animating {
background-color: #fff;
-moz-transition: background-color 1s linear;
-ms-transition: background-color 1s linear;
-o-transition: background-color 1s linear;
-webkit-transition: background-color 1s linear;
transition: background-color 1s linear;
}
答案 1 :(得分:4)
该代码段存在多处错误
background-color
jquery不支持彩色动画,请检查jquery ui以获得支持 http://jqueryui.com/animate/
$(document).ready(function() {
$('#res').hover(
function () {
$(this).animate({"font-size": "90px" });
},
function () {
$(this).animate({"font-size" : "12px" });
}
);
});
答案 2 :(得分:0)
删除动画
$('#res').hover(
function () {
$(this).css("background","#fff");
},
function () {
$(this).css("background","#000");
}
);
更好的方法是更改选择器的类
$('#res').hover(
function () {
$(this).addClass("on");
},
function () {
$(this).removeClass("on");
}
);
答案 3 :(得分:0)
$(document).ready(function() {
$('#res').hover(
function () {
$(this).css('background-color' ,'#fff');
},
function () {
$(this).css('background-color' ,'#000');
})
});