jQuery slideDown() 动画不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17566534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery slideDown() animation not working
提问by Ahmad
I'm trying to get jQuery's slideDown()
animation to work, but in my case the text that should slide down, just appears.. How do I make it appear with the animation in place too ?
我试图让 jQuery 的slideDown()
动画工作,但在我的情况下,应该向下滑动的文本只是出现..我如何让它在动画就位的情况下出现?
I tried manually specifying the speed too, but end result was the same.
我也尝试手动指定速度,但最终结果是一样的。
HTML:
HTML:
<section class="subscribe">
<button id="submitBtn" type="submit">Subscribe</button>
<p></p>
</section>
JavaScript:
JavaScript:
$(function () {
$("#submitBtn").click(function (event) {
$(".subscribe p").html("Thanks for your interest!").slideDown({
duration: 4000
});
});
});
JSFiddle:http://jsfiddle.net/ahmadka/A2mmP/
JSFiddle:http : //jsfiddle.net/ahmadka/A2mmP/
回答by fehnomenal
Your p
element is already displayed when you enter the text and try to slide it down. So no animation is needed.
p
当您输入文本并尝试将其向下滑动时,您的元素已显示。所以不需要动画。
$(function () {
$("#submitBtn").click(function (event) {
$(".subscribe p").hide().html("Thanks for your interest!").slideDown(4000);
});
});
回答by Alvaro
You can do it having the content hidden at first and then just showing it with the slideDown
function:
你可以先隐藏内容,然后用slideDown
函数显示它:
HTML
HTML
<section class="subscribe">
<button id="submitBtn" type="submit">Subscribe</button>
<p>Thanks for your interest!</p>
</section>
CSS
CSS
.subscribe p{
display:none;
}
jQuery
jQuery
$(function () {
$("#submitBtn").click(function (event) {
$(".subscribe p").slideDown({duration: 400});
});
});
Living example: http://jsfiddle.net/A2mmP/2/
活生生的例子:http: //jsfiddle.net/A2mmP/2/