2

I have tried spinning and sliding seperately and they work fine. But when I combine them they have an awkward combo.

http://jsfiddle.net/62RJc/268/

img{

    border-radius:50%;  
    -webkit-transition: -webkit-transform .8s ease-in-out;
    -ms-transition: -ms-transform .8s ease-in-out;
    transition: transform .8s ease-in-out;
}
2
  • 1
    What does "awkward" mean...what are you expecting. Commented Jun 12, 2015 at 15:56
  • there was a lot of flickering but @Aramil Rey seemed to have solved it Commented Jun 12, 2015 at 17:34

1 Answer 1

2

Its because you are using keyFrame, you can achieve this with transform alone.

Take a look at this: (Also, hovering an img while its moving is not an easy task)

img{
    border-radius:50%;    
    -webkit-transition: -webkit-transform .8s ease-in-out;
    -ms-transition: -ms-transform .8s ease-in-out;
    transition: transform .8s ease-in-out;    
}

button:hover + img {
    position: relative;
    transform: translateX(200px) rotate(360deg);
}
<button>Animate!</button>
<img src="http://lorempixel.com/output/nature-q-c-100-100-9.jpg"/>

To make image stay where it is after animation ended: 1) Remove button:hover + img {} from CSS 2) Add JS

JQuery:

$('button').click(function() {
    $('img').css('transform', 'translate(200px) rotate(360deg)');
});

JS Fiddle - Element not returning to starting position!

Sign up to request clarification or add additional context in comments.

3 Comments

is there anyway to stop it from rotating back?
You are adding CSS to the element only while 'button:hover' is being triggered, you should add those styles permanently with JS to make the image stay where it was after the animation
I just wanted to make it rotate and stop with a display: none. for example: it rotates, stops, then clears.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.