Javascript JQuery:如何确定 Slide 事件是向上还是向下?

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

JQuery: How to determine if Slide event is up or down?

javascriptjquery

提问by JGreig

I have the following code:

我有以下代码:

$('a.btn-slide').toggle(function() {
    $("#DivToSlide").slideUp("fast");
    // ...
}, function() {
    $("#DivToSlide").slideDown("fast");
    // ...
});

Later in my code, I want to find out if #DivToSlideis in either the upor downposition.

在我的代码后面,我想知道#DivToSlide是在向上还是向下的位置。

How do I do that?

我怎么做?

回答by SLaks

Since the slideDownfunction hides the element after it finishes, you can simply check whether the element is visible:

由于slideDown函数在完成后隐藏元素,你可以简单地检查元素是否可见:

if ($('#DivToSlide').is(':visible'))

You could also check whether $('#DivToSlide').height()is more than some threshold.

您还可以检查是否$('#DivToSlide').height()超过某个阈值。

回答by Avinash Saini

if($(this).next('.nxt_div').height()>1){ }