我编写了该方法fadeIn
,fadeOut
并且我知道它在 jQuery 中,但这是一种实践,所以我想向该fadeIn
方法添加一个参数:
function fadeIn(e, time) {
// e.style.opacity = 1;
var op = Number(getComputedStyle(e).opacity).toPrecision(2);
e.style.opacity = op;
if (op >= 1) {
return;
}
e.style.opacity = Number(op) + 0.01;
setTimeout(function() {
fadeIn(e)
}, time)
}
function fadeOut(e) {
// e.style.opacity = 0;
var op = Number(getComputedStyle(e).opacity).toPrecision(2);
e.style.opacity = op;
if (op <= 0) {
return;
}
e.style.opacity = Number(op) - 0.01;
setTimeout(function() {
fadeOut(e)
}, 10)
}
Element.prototype.fadeIn = function(time) {
fadeIn(this, time);
};
Element.prototype.fadeOut = function() {
fadeOut(this);
};
您必须在正在进行的通话中传递时间:
setTimeout(function () {
fadeIn(e, time); // <<<
}, time)
现在这是将不透明度增加 1/100 的间隔时间,因此您可能也想划分时间:
Element.prototype.fadeIn = function (time) {
fadeIn(this,time / 100);
};
所以现在
el.fadeIn(1000);
将需要一秒钟淡入。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句