Oliver
Oliver

Reputation: 441

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

Upvotes: 3

Views: 88

Answers (3)

user11086029
user11086029

Reputation:

try to modify timing effects like ease out bounce

change it to ease in

Upvotes: 0

user11085994
user11085994

Reputation:

This function should work:

$('#img').hover(
  function() {
    $(this).animate({
      borderRadius: 75
    }, 300, 'easeOutBounce');
  },
  function() {
    $(this).animate({
      borderRadius: 5
    }, 300, 'easeOutBounce');
  }
);

Upvotes: 1

Pingolin
Pingolin

Reputation: 3417

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

Upvotes: 2

Related Questions