O
O
Outoverlay2015-10-30 16:00:49
JavaScript
Outoverlay, 2015-10-30 16:00:49

How to create an equivalent fadeOut jQuery function?

I looked at the jQuery sources, there is a lot of code, starting with fadeOut: { opacity: "hide" },
ending with jquery.speed and jquery.animation. I tried to create something according to my logic - It turned out:

function fadeOut(time){
var opacity,
timelength = '' + time,
i;
d='';
for( var i = 0; i <= timelength.length-2; i++ ){
d+='0';
}
s = timelength.substring(0,1);
timez = s + d;
console log(timez);
timeOne = '0.'+d+'1';
timec = '0.'+time;
timelength = timelength.length;

each(function(){
ele = this;
setInterval(function(){
opacity = getComputedStyle(ele).opacity;
if(opacity == 0){
ele.style.opacity = 'none';
ele.style.display = ' none';
return ele;
}else{
ele.style.opacity = opacity - timeOne;
}
}, time);

});
}

The problem is the response speed does not work on time.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2015-10-30
@twobomb

Here I made my fadeOut, see if you like it
https://jsfiddle.net/6g8u0qsw/4/

S
Super User, 2015-10-30
@sergeystepanov1988

FadeIn suggested by You Might Not Need JQuery

function fadeIn(el) {
  el.style.opacity = 0;

  var last = +new Date();
  var tick = function() {
    el.style.opacity = +el.style.opacity + (new Date() - last) / 400;
    last = +new Date();

    if (+el.style.opacity < 1) {
      (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16)
    }
  };

  tick();
}

fadeIn(el);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question