本文介绍了slideToggle()可以检测SlideUp或SlideDown吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道hover()具有handInhandOut的默认设置,但是无论如何我可以检测到SlideToggle内部的slideUpSlideDown吗?

I know hover() has default setting for handIn and handOut, but is there anyway I could detect slideUp and SlideDown inside SlideToggle?

具有这样的代码:

$("#divName").slideToggle(function(){//when slideUp, do something},
                          function(){//when slideDown, do something});

我尝试了这段代码,但是没有运气,你们是否认为这有时会使事情变得容易一些?

I tried this code but no luck, do you guys think this may sometimes make things a bit easier ?

推荐答案

slideToggle不允许默认设置,但是编写您自己的版本很容易.这样的事情将在您替代处理程序时起作用:

slideToggle doesn't allow for that as default, but it would be easy enough to write your own version. Something like this would work as you alternative handler:

$('#divTrigger').click(function () { // Or bind to any other event you like, or call manually

    var $t = $('#divToSlide');

    if ($t.is(':visible')) {
        $t.slideUp();
        // Other stuff to do on slideUp
    } else {
        $t.slideDown();
        // Other stuff to down on slideDown
    }
});

同样,如果您希望动作在slideUp或slideDown之后发生,则可以将其放入回调中,例如$.slideUp(300, function() {// Callback here});.

Equally, if you wanted actions to happen after slideUp or slideDown, you could put them into the callback, like this $.slideUp(300, function() {// Callback here});.

这篇关于slideToggle()可以检测SlideUp或SlideDown吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 23:54