onHide() type event in jQuery

Does anyone know of an onHide() event or something similar in jQuery?

I tried:

$(this).bind('hide', function(){
    console.log('asdasda')
})

But apparently that doesn't work.

Edit: Just to clarify, it's being hidden using CSS display:none .
I'm aware of the callback function but as I'm not hiding it (the CSS is) I can't use it. For what it's worth, I need to check when a dropdown is visible. It's being shown by the following CSS:

ul li:hover ul {
    display: block;
} 

There is no "hide" event for any HTML element in the DOM. How are you "hiding" your elements? Are you using CSS to change the display or visibility?

If you're using display:none to hide an element, you can't detect when CSS changes. In IE, you can detect when a property changes but that doesn't extend to style values. You'll need to throw an event or do whatever the event is doing at the time the CSS display is changed.


没有本地或内置的“隐藏”事件,但如果您使用jQuery来隐藏它,则可以轻松添加隐藏事件:

var _oldhide = $.fn.hide;
$.fn.hide = function(speed, callback) {
    $(this).trigger('hide');
    return _oldhide.apply(this,arguments);
}

您可以在隐藏功能中传递回调函数。

function iAmCallBackForHide() { 
             alert('I am visible after hide'); 
}
$('#clickMeToHide').hide( iAmCallBackForHide );
链接地址: http://www.djcxy.com/p/83380.html

上一篇: 元素变得可见时jQuery

下一篇: jQuery中的onHide()类型事件