You might want to make keyframes setup in css and add the id or class to the element
Example for calling a keyframe:
.myElement{
position:absolute;
background:blue;
-webkit-animation:KeyframeName 1s linear infinite;
}
Example for a keyframe:
@-webkit-keyframes KeyframeName {
0%{style code here, example: opacity:1;}
100%{style code here, example: opacity:0;}
}
The only down sides are:
- you have to make a keyframe setup for all browsers.
- on mobile devices it takes alot of power, meaning you page becomes un-touchable or onclickable. And makes it hard to use many keyframes at once.
Or
Try making a function in javascript and put this code in it:
var OpacityValue = 1;
function OpacityChange(){
if(OpacityValue == 0.0){
Opacity = 0.0;
clearInterval(TimerName);
}
else if(OpacityValue > 0){
OpacityValue += -0.1;
}
yourElement.style.opacity = OpacityValue;
}
Launch this function with a timer an you got you opacity that will stop when its at a value of 0.0
Don't forget to place a var TimerName ; as global, otherwise you cant stop the timer!