jQuery FadeIn不起作用 [英] jquery fadeIn not working
本文介绍了jQuery FadeIn不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我我做错了吗
Can someone please tell me what I'm doing wrong:
样式:
.warning{border: 1px solid #F0AAAA; background:#FFBABA; color: #C90000;}
标记:
<p class="warning">A successful authorization already exists.
Further authorizations are not allowed at this time.</p>
脚本:
$().ready(function () {
alert($(".warning").html()); // WORKS
$(".warning").fadeIn(4000); // DOESN'T WORK
});
推荐答案
除非隐藏了元素,否则不会发生褪色,您需要这样的东西:
Unless the element is hidden, no fade will occur, you need something like this:
$(".warning").hide().fadeIn(4000);
您可以在此处尝试,并且$()
在1.4+版本中已弃用,您应该使用$(document)
或更短的版本,例如:
You can give it a try here, also $()
is deprecated in 1.4+, you should use $(document)
or the shorter version, like this:
$(function() {
$(".warning").hide().fadeIn(4000);
});
另一种方法是最初为元素赋予display: none
,但是对于禁用了JS的用户来说,这会中断,或者如果发生JavaScript错误而阻止了淡入淡出,那么您可能想避免使用此方法
The alternative is to give the element a display: none
initially but this breaks for JS-disabled users, or if JavaScript errors occur preventing the fade, so you may want to steer clear of this approach.
这篇关于jQuery FadeIn不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文