开发者

Custom jQuery event listener that triggers on show()

I have a div that gets hidden and displayed, via .hide() and .show(). When it is displayed by .show() I need it t开发者_如何学编程o do some stuff. Is there any way I can setup a custom event listener that fires a callback when the div goes from hidden to visible? I can make a function and call it wherever I would call $(#myDiv").show() but that happens in multiple places and I would like to keep this all in one place.


You can pass a function callback into the show method which will execute after the show has completed:

$("#myDiv").show(function(){
   myCustomFunction();
});


You could use you own function instead of the internal "show" with a specific callback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜