My fadeOut is ok, but fadeIn is not working ...
function fadeIn(elem, speed)
{
if(!elem.style.opacity)
{
elem.style.opacity = 0;
}
InInterval(function(){
elem.style.opacity += 0.03;
}, speed /100);
}
My fadeOut is ok, but fadeIn is not working ...
function fadeIn(elem, speed)
{
if(!elem.style.opacity)
{
elem.style.opacity = 0;
}
InInterval(function(){
elem.style.opacity += 0.03;
}, speed /100);
}
The problem is that the opacity value is interpreted as a string (text), not a number. You can like :
function fadeIn(elem, speed) {
if(!elem.style.opacity) {
elem.style.opacity = 0;
}
timer = setInterval(function(){
if(parseFloat(elem.style.opacity) >= 1) clearInterval(timer);
elem.style.opacity = parseFloat(elem.style.opacity) + 0.03;
}, speed / 100);
}
ele = document.getElementById('hey');
fadeIn(ele, 5000);
#hey {
background-color: red;
width: 100px;
height: 100px;
}
<div id="hey">
</div>