Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

jquery fadeIn not working

Can someone please tell me what I'm doing wrong:

style:

.warning{border: 1px solid #F0AAAA; background:#FFBABA; color: #C90000;}

markup:

 <p class="warning">A successful authorization already exists. 
                    Further authorizations are not allowed at this time.</p>

script:

 $().ready(function () {
     alert($(".warning").html());     // WORKS
     $(".warning").fadeIn(4000);      // DOESN'T WORK
 });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unless the element is hidden, no fade will occur, you need something like this:

$(".warning").hide().fadeIn(4000);

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);
});

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...