[英]JQuery fadeTo() function doesn't work correctly on both elements
I can't understand why the .quote-container
opacity is higher than #new-quote
if they are in the same fadeTo()
function brackets and duration is the same. 我不明白为什么
.quote-container
不透明度为什么比#new-quote
如果它们位于相同的fadeTo()
函数括号中,并且持续时间相同。
What I mean, that during fadeTo()
animation, .quote-container
and #new-quote
opacity should be same, for example: opacity: 0.12 and opacity: 0.12, so they should stop and start at the same time. 我的意思是,在
fadeTo()
动画过程中, .quote-container
和#new-quote
不透明度应该相同,例如:opacity:0.12和opacity:0.12,因此它们应该同时停止并开始。 But now, it's like opacity: 0.12 and opacity: 0.20. 但是现在,它就像不透明度:0.12和不透明度:0.20。
#new-quote
element opacity should be the same as the first element. #new-quote
元素的不透明度应与第一个元素相同。
There is my codepen: See the Pen BJLPEV by Lukas ( @Kestis500 ) on CodePen . 还有就是我codepen:见笔BJLPEV由卢卡斯( @ Kestis500上) CodePen 。
Unfortunately, I can't upload a video showing what is going on but the css opacity on both elements are the same: 0. 不幸的是,我无法上传视频以显示正在发生的事情,但是两个元素的css不透明度相同:0。
This line of code should be broken somehow: 此行代码应以某种方式破坏:
getQuote().done(setTimeout(function() {
$("#new-quote").outerHeight($(".quote-container").outerHeight());
}, 1000), $(".quote-container, #new-quote").fadeTo(10000, 1));
$(".quote-container, #new-quote").fadeTo(10000, 1));
What am I doing wrong? 我究竟做错了什么?
The issue is on these lines 问题在这些线上
$("body, .button").animate({
"background-color": colors[randomNumber]
});
$(".quote-text, .quote-author, #new-quote").animate({
color: colors[randomNumber]
});
You are applying animate separately on #new-quote that cause delay in rendering. 您正在对#new-quote单独应用动画,这会导致渲染延迟。 Either remove animation on #new-quote or add dummy animation to .quote-container.
删除#new-quote上的动画或将虚拟动画添加到.quote-container。 Change the above to
将以上更改为
$("body, .button").animate({
"background-color": colors[randomNumber]
});
$('.quote-container').animate({
"padding": "2.5rem"
});
$(".quote-text, .quote-author, #new-quote").animate({
color: colors[randomNumber]
});
$('.quote-container').animate({
"padding": "2.5rem"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.