<分区>
<分区>
<!DOCTYPE html>
<html>
<head>
<title>Alive Time</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="code.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
</head>
<body>
<i class="fa fa-cog" style="font-size:100px"></i>
<i class="fa fa-arrow-right" style="font-size:100px"></i>
</body>
</html>
----------------------------------------------------------------------------
.fa-cog{
margin: 10% 50%;
color: red;
/*-moz-transition: all 0.5s linear;
-webkit-transition: all 0.5s linear;
transition: all 0.5s linear;*/
}
.down {
-moz-transform:rotate(180deg);
-webkit-transform:rotate(180deg);
transform:rotate(180deg);
}
--------------------------------------------------------------------------------------------------------------
$(document).ready(function(){
$(".fa-cog").on('mouseenter',function(){
$(this).animate({rotate:180},{
step:function(now,fx){
/*$(this).css({' -moz-transform':'rotate('+now+'deg)',
'-webkit-transform':'rotate('+now+'deg)',
'transform':'rotate('+now+'deg)'});*/
$(this).css('-webkit-transform','rotate('+now+'deg)');
$(this).css('-moz-transform','rotate('+now+'deg)');
$(this).css('transform','rotate('+now+'deg)');
},duration:'slow'},'linear');
});
});
伙计们,我正在尝试专门使用 jquery 的 animate() 方法来旋转齿轮。我知道我可以让一个类使用一些转换、转换然后添加或删除该类。但我想在这里使用 animate() 。 stackoverflow 上的几个文档说我们实际上不必使用真正的 CSS 属性,例如文本索引或边框间距,而是您可以指定一个伪造的 CSS 属性,例如旋转或 my-awesome-property 或其他。使用将来不会成为实际 CSS 属性的风险可能是个好主意。我尝试了一切都无法在我的代码中找到错误。忽略我注释掉的代码。
最佳答案
问题出在这一行:
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
在您的情况下,您不能使用 jQuery 的精简版,因为该版本没有动画。只需将其替换为:
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
关于javascript - jQuery animate() 显示错误 $(...).animate 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47325644/