问题描述
我想以某种方式获得褪色元素的目标不透明度(它被动画化的最终值)。
I'd like to somehow get the target opacity (the final value it is being animated to) of an element that is fading.
例如......
$('body').fadeTo(0.4); // 0.4
$('body').fadeIn(); // 1
$('body').fadeOut(); // 0
$('body').animate({ opacity: 0.7 }); // 0.7
这在jQuery中是否可行?
Is this doable in jQuery?
对于某些背景,请参阅我的回答。我试图在SO上帮助另一个用户,并决定问这个与我的答案有关的问题。
For some background, see my answer here on Stack Overflow. I was trying to help out another user on SO and decided to ask this question that related to my answer.
推荐答案
jQuery使用步骤在内部函数中,您可以覆盖 jQuery.fx.step.opacity
函数来读取传递的 jQuery.fx
对象:
jQuery uses step functions internally, you can overwrite the jQuery.fx.step.opacity
function to read the passed jQuery.fx
object:
var old = jQuery.fx.step.opacity;
jQuery.fx.step.opacity = function( fx ) {
console.log(fx.elem);
console.log(fx.end);
return old(fx);
};
在每个不透明度动画的每一步调用不透明度步长函数。您可能希望根据 fx.elem
过滤上述内容。
The opacity step function is called on every step of every opacity animation. You would probably want to filter the above based on fx.elem
.
fx。结束
是动画的最终值, fx.now
是当前值, fx.start
是起始值。 fx.unit
是值的单位(以px,em,%等表示)。
fx.end
is the final value of the animation, fx.now
is the current value and fx.start
is the starting value. fx.unit
is the unit of the values (in px, em, %, etc).
这篇关于在jQuery中,你能得到“目标”吗?褪色元素的不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!