jQuery:slideUp() delay() 然后slideDown;不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3833076/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:11:42  来源:igfitidea点击:

jQuery: slideUp() delay() then slideDown; not working

jquerydelayslideupslidedown

提问by Ryan

I'm trying to implement a very simple footer notification element to slide up for a moment, then slide back down. I'm using:

我正在尝试实现一个非常简单的页脚通知元素,使其向上滑动片刻,然后再向下滑动。我正在使用:

$('button').click( function () {
    $('#message-box').slideUp('slow').delay(1500).slideDown('slow');
});

However, when you click the button, it delays for the 1500 ms then slides up and never slides down.

但是,当您单击该按钮时,它会延迟 1500 毫秒,然后向上滑动并且从不向下滑动。

http://jsfiddle.net/jrMH3/17/

http://jsfiddle.net/jrMH3/17/

回答by Nick Craver

What you actually want is this:

你真正想要的是这样的:

 $('#message-box').slideDown('slow').delay(1500).slideUp('slow');

You can test it here. Though it seems a bit backwards given your layout, .slideDown()is for showingan element, and .slideUp()is for hidingan element...even though given your CSS it's actually going up when shown.

你可以在这里测试。尽管考虑到您的布局,它似乎有点倒退,.slideDown()用于显示一个元素,并且.slideUp()用于隐藏一个元素......即使给定您的 CSS,它实际上在显示时会上升。

Also as an aside, you don't need <html>and <body>tags when editing the fiddle, these are already included...any content in the html frame will go inside the <body>.

另外顺便说一句,编辑小提琴时不需要<html><body>标签,这些已经包含在内......html框架中的任何内容都将进入<body>.