Continuous CSS rotation animation on hover, animated back to 0deg on hover out
The solution is to set the default value in your .elem.
But this annimation work fine with -moz but not yet implement in -webkit
Look at the fiddle I updated from yours :
http://jsfiddle.net/DoubleYo/4Vz63/1648/
It works fine with Firefox but not with Chrome
.elem{ position: absolute; top: 40px; left: 40px; width: 0; height: 0; border-style: solid; border-width: 75px; border-color: red blue green orange; transition-property: transform; transition-duration: 1s;}.elem:hover { animation-name: rotate; animation-duration: 2s; animation-iteration-count: infinite; animation-timing-function: linear;}
@keyframes rotate { from {transform: rotate(0deg);} to {transform: rotate(360deg);}}
<div class="elem"></div>
How to continuously rotate an icon on hover?
Try this I hope this works for you
<!DOCTYPE html>
<html>
<head>
<style>
i:hover {
animation: rotation 3s infinite linear;
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
</style>
<title>My Project</title>
</head>
<body>
<div>
<i class="fa fa-times"/>
</div>
</body>
</html>
Pause CSS animation and change the animated property on hover - but don't restart another animation on mouse leave
ok as long as you didn't replied yet, here is your solution, i hope it meets your code aims, regards,
$(document).ready(function(){
$(".button").css("animation", "fadeInBottom 1s");
setTimeout(function(){
$(".button").css("animation", "fadeInOutShadow ease-in-out 1.2s alternate infinite");
}, 1200);
});
$(".button").hover(function(){
$(".button").css({"animation": "0", "box-shadow": "0 0 35px rgba(250, 215, 0, 0.9)"});
}, function(){
$(".button").css({"box-shadow": "", "animation": "fadeInOutShadow ease-in-out 1.2s alternate infinite"});
});
.button {
&:hover {
box-shadow: 0 0 35px rgba(255, 215, 0, 0.9);
}
}
@keyframes fadeInBottom {
0% {
opacity: 0;
-webkit-transform: translateY(10px);
transform: translateY(10px);
}
100% {
opacity: 1;
-webkit-transform: translateY(0);
transform: translateY(0);
}
}
@keyframes fadeInOutShadow {
0% {
-webkit-box-shadow: 0 0 25px rgba(255, 215, 0, 0.5);
box-shadow: 0 0 25px rgba(255, 215, 0, 0.5);
}
100% {
-webkit-box-shadow: 0 0 25px rgba(255, 215, 0, 0.8);
box-shadow: 0 0 25px rgba(255, 215, 0, 0.8);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="button">Button</button>
css3 animation on :hover; force entire animation
I'm afraid that the only way to solve this is with a bit of javascript, you must add the animation as a class and then remove it when the animation finishes.
$(".box").bind("webkitAnimationEnd mozAnimationEnd animationend", function(){
$(this).removeClass("animated")
})
$(".box").hover(function(){
$(this).addClass("animated");
})
http://jsfiddle.net/u7vXT/
Animation rotate from 360deg to 0deg - iOS sensor
So I am answering my own question after some time to explain how I resolved this issue.
This solution doesn't use React's Animation framework (nor the nativeDriver) but it uses useAnimationFrame callback. So we won't be touching the issue with interpolation method.
Instead I opted for calculating the distance to the desired heading (from a sensor) between rotating left and rotating right by "step" amount. It's called cyclic distance and it's implemented something like this:
function cyclicDistance(current: number, now: number): number {
const abs = Math.abs(current - now);
const distanceAround = 360 - abs;
const distanceStraight = abs;
const distance = Math.min(distanceAround, distanceStraight);
return distance;
}
So we are getting the shortest path via Math.min of the two possible solutions.
I am using Reference (useRef Hook) to store current value of heading.
Next we are calculating two distances:
The first one - base distance - is cyclic distance between current sensor value and our current heading value.
The second one is used resolving "tendency" like asking "if we increase our heading by 1 (step) would the cyclic distance increase or decrease?"
const baseDistance = cyclicDistance(
sensorHeading,
myHeadingRef
);const tendency =
cyclicDistance(sensorHeading + 1, myHeadingRef) < baseDistance
? 1
: -1;
The last piece of the puzzle is value wraparound. We are allowing the value of degrees to be higher than 360 or lower than 0. React's CSS rotate transformation can handle that, so we can make use of it.
if (myHeading.current < 0) {
myHeading.current += 360;
} else if (myHeading.current > 360) {
myHeading.current -= 360;
}
Putting it all together:
function cyclicDistance(current: number, now: number): number {
const abs = Math.abs(current - now);
const distanceAround = 360 - abs;
const distanceStraight = abs;
const distance = Math.min(distanceAround, distanceStraight);
return distance;
}
const [heading, setHeading] = useState(0);
const myHeading = useRef<number>(0);
const locationRef = useRef<Array<number>>([0, 0]);
const step = () => {
if (myHeading.current < 0) {
myHeading.current += 360;
} else if (myHeading.current > 360) {
myHeading.current -= 360;
}
const maxDistance = 10;
const distance = cyclicDistance(
myHeading.current,
locationRef.current[1]
);
const tendency =
cyclicDistance(myHeading.current + 1, locationRef.current[1]) <
distance
? 1
: -1;
const move = distance > maxDistance ? maxDistance : distance;
const newpos = myHeading.current + tendency * move;
myHeading.current = newpos;
setHeading(myHeading.current);
};
useAnimationFrame(() => step(), []);
It might need a little bit of refactoring to increase readability, but its good enough for you the get the idea.
Related Topics
Css3 Combining Selectors with or Instead of And
How to Apply a Style to All Children of an Element
First-Child Full-Width in Flexbox
Css: Clean Solution to the Margin Collapse Issue When Floating an Element
Custom.CSS Has Stopped Working in 32.0.1700.76 M Google Chrome Update
Why on Safari the Transform Translate Doesn't Work Correctly
Nesting Pseudo-Elements Inside Pseudo-Elements
How to Make a Column Span Full Width When a Second Column Is Not There? (CSS Grid)
Can You Target an Element with CSS Only If 2 Classes Are Present
CSS Select First Element with a Certain Class
How to Do Knock-Out/Punch-Through Transparency with CSS Fonts