[英]Animated css change (jQuery)
I was trying apply jQuery easing plugin to .css and .animate, but not working, i dont know why, because normally it works. 我试图将jQuery宽松插件应用于.css和.animate,但无法正常工作,我不知道为什么,因为通常它可以正常工作。 Code example:
代码示例:
$('#img').hover(function() {
$(this).animate({"border-radius":"5px"}, 0, "easeOutBounce");
}, function() {
$(this).animate({"border-radius":"75px"}, 0, "easeOutBounce");
});
So basically .animate (instead of .css to avoid problems) but i want also set animation duration and working "easeOutBounce"
or some of other effects. 所以基本上是.animate(而不是.css以避免问题),但我还想设置动画持续时间并工作
"easeOutBounce"
或其他一些效果。
Now border radius is animated on :hover
, but without animation timing. 现在,边框半径已在
:hover
上设置了动画,但没有动画定时。
I cannot do it in css, and jQuery is not working, is there some way to fix this? 我无法在CSS中执行此操作,并且jQuery无法正常工作,是否有某种方法可以解决此问题?
Thanks, Oliver 谢谢,奥利弗
I think the syntax you are using in your animation is not correct. 我认为您在动画中使用的语法不正确。 Also, you need to set a duration > 0 if you want to see something.
另外,如果要查看内容,则需要将持续时间设置为> 0。
Feel free to change the easing
part with your own plugin. 可以使用自己的插件随意更改
easing
部分。
$('#img').hover( function() { $(this).animate({ borderRadius: 75 }, 300, 'easeOutBounce'); }, function() { $(this).animate({ borderRadius: 5 }, 300, 'easeOutBounce'); } );
#img { border-radius: 5px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js"></script> <img id="img" src="https://i.stack.imgur.com/Qk0jX.jpg">
This function should work: 此功能应该起作用:
$('#img').hover(
function() {
$(this).animate({
borderRadius: 75
}, 300, 'easeOutBounce');
},
function() {
$(this).animate({
borderRadius: 5
}, 300, 'easeOutBounce');
}
);
try to modify timing effects like ease out bounce
尝试修改定时效果,例如
ease out bounce
change it to ease in
改变它以
ease in
I've tried a sample that works the way it is. 我尝试了一个按原样工作的示例。
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="block"></div>
<div class="block"></div>
$('div.block').hover(function(){
$(this).animate({ borderRadius: '70px' }, 600, 'easeInBounce');
},function(){
$(this).animate({ borderRadius: '0px' }, 600, 'easeOutBounce');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.