简体   繁体   English

jQuery onhide事件处理程序

[英]jQuery onhide event handler

In jQuery, I'm hiding my elements using .hide(); 在jQuery中,我使用.hide();隐藏了我的元素.hide(); .

Is there an evert handler that is fired when I hide something? 当我隐藏某些内容时是否会触发一个外部处理程序? You see, I have a bunch of elements in my code, and I'm hiding them or showing them (using jQuery) a bunch of times. 你看,我的代码中有很多元素,我隐藏了它们或者用它们(使用jQuery)多次显示它们。 To keep things in check, in an efficient way, I would love to use an event handler for .hide() 为了有效地控制事情,我希望为.hide()使用事件处理程序

Could someone point me in the right direction for this? 有人能指出我正确的方向吗?

Many Thanks! 非常感谢!

You can use a callback function 您可以使用回调函数

$('#element').hide('slow', hideCallback);

$('#element').show('slow', showCallback);

function hideCallback()
{
    // You can do your stuff here
}

function showCallback()
{
    // You can do your stuff here
}
$('p').on('ohWowIGotHidden', function(){
    document.write('O look, it works');
});

$('p').hide(function(){
    $(this).trigger('ohWowIGotHidden');
});

​You can create a custom event and trigger it whenever you call the hide method.. 您可以创建自定义事件,并在调用hide方法时触发它。

您可以在调用原始函数后重写隐藏在jquery中以调度事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM