jQuery 淡入()
如果淡入淡出时间一到,fadeIn() 的不透明度就从 0% 变为 100%,这意味着什么?
我得到了这个:
function ThreadPost(post, appendToElementId) {
if (post != null) {
$("#" + appendToElementId).append("<ol id='" + post.Id + "'></ol>");
$("#" + post.Id).hide().html(PostHtml(post)).fadeIn(5000);
}
}
PostHtml() 返回一个“
页面加载时,
被隐藏。 然后,5 秒后,
突然出现。 不会出现褪色现象。 使用 Chrome。What does it mean if fadeIn() goes from an opacity of 0% to 100% as soon as the fade timeperiod is up?
I've got this:
function ThreadPost(post, appendToElementId) {
if (post != null) {
$("#" + appendToElementId).append("<ol id='" + post.Id + "'></ol>");
$("#" + post.Id).hide().html(PostHtml(post)).fadeIn(5000);
}
}
PostHtml() returns a "<li>....</li>
".
When the page loads, the <ol>
is hidden. Then, after 5 seconds, the <ol>
suddenly appears. No fading occurs. Using Chrome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我遇到过各种奇怪的问题,jQuery fadeIn() 和 show() 只是弹出而不是动画。 看看这样是否效果更好:
I've had all kinds of weird issues with jQuery fadeIn() and show() just popping in instead of animating. See if this works better:
你能尝试取出
hide()
并让我知道它的作用吗? 或者也许将hide()
移至设置 html 之后? 无论如何,fadeIn 方法应该自动隐藏它,但值得一试。另外,您能否提供有关
PostHtml
方法的更多信息? 可能是它定义的风格导致了事情的行为变得奇怪。Can you try taking out the
hide()
and let me know what it does? Or perhaps move thehide()
to after you set the html? The fadeIn method should hide it automatically anyway, but it's worth a shot.Also, can you provide any more information about what the
PostHtml
method does? It could be that it's defining styles that are making things behave strangely.我同意 @Damovisa 的观点,因为我们可以了解 PostHtml 方法的作用 - 如果它执行 Ajax 调用,那么它可能会在 fadeIn 超时到期后完成,因此,淡入淡出效果似乎不起作用。
I agree with @Damovisa in that we could do with knowing what the PostHtml method does - if it does an Ajax call then it might be completing after the fadeIn timeout has expired, hence the fading in effect not appearing to work.
尝试将 PostHtml(post) 硬编码为
。 请参见下文:
如果这适用于硬编码的
,那么您就知道是 PostHtml(post) 导致了您的问题。 当我进行硬编码时,淡入淡出效果在 IE、FF 和 Chrome 中按预期工作。
Try hardcoding PostHtml(post) as
<li>test</li>
. See below:If that works with the hardcoded
<li>
, then you know it's PostHtml(post), causing your issue. When I hard code, the fade works as expected in IE, FF, and Chrome.您是否尝试过在 fadeIn(): 之前调用 show():
或者干脆去掉 hide():
Have you tried calling show() right before fadeIn():
or simply get rid of the hide():