我的JQuery: //script.js
$(document).ready(
function()
{
$(".image").bind('mouseenter',
function()
{
$(this).stop().animate(
{
backgroundColor: "blue"
},
{
queue:false,
duration:300,
easing: "swing"
});
});
$(".image").bind('mouseleave',
function()
{
$(this).stop().animate(
{
backgroundColor: "green"
},
{
queue:false,
duration:300,
easing: "swing"
});
});
});
HTML: //index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css"></link>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div class="image"></div>
</body>
</html>
CSS: //样式表.CSS
body
{
background-image: url("background.jpg");
margin:0 auto;
padding:0;
}
.image
{
background-color: green;
width: 100px;
height: 100px;
}
div没有什么作用,但是如果我用css()来尝试它,它就能工作了!我怎么才能解决这个问题?所有的东西都会被正确的调用,即使是在动画()之后(我添加了一个警报()来检查lol),所以我不知道为什么.
发布于 2014-02-10 23:26:22
来自正式的jQuery文档:
所有动画属性都应该动画为单个数值,除非如下所述;大多数非数字属性不能使用基本的jQuery功能进行动画(例如,宽度、高度或左侧可以是动画,但是背景色不能是,除非使用jQuery.Color()插件)。除非另有规定,属性值被视为若干像素。在适用的情况下,可以指定单位em和%。
http://api.jquery.com/animate/
我建议使用CSS3转换来达到同样的效果。jsFiddle示例这里。
.image {
background-color: green;
width: 100px;
height: 100px;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
对于过渡宽松,您可以查看此链接。
https://stackoverflow.com/questions/21689880
复制相似问题