Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

Now border radius is animated on :hover, but without animation timing.

I cannot do it in css, and jQuery is not working, is there some way to fix this?

Thanks, Oliver

like image 601
Oliver Avatar asked Apr 17 '26 18:04

Oliver


1 Answers

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.

Feel free to change the easing part with your own plugin.

$('#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.sstatic.net/Qk0jX.jpg">
like image 55
Armel Avatar answered Apr 19 '26 07:04

Armel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!