jquery event handler: div becomes visible/hidden

前端 未结 2 1684
执念已碎
执念已碎 2020-12-11 15:43

I have a div and I\'d like to have an event handler listen to when it becomes visible and hidden. How do you do that?

Thanks.

2条回答
  •  一向
    一向 (楼主)
    2020-12-11 16:13

    You can use the callback parameter in the show() and hide() methods like this:

    $('#myDiv').show(0, onDivShow);
    $('#myDiv').hide(0, onDivHide);
    
    function onDivShow() { //your code here }
    function onDivHide() { //your code here }
    

    See a working example here: http://jsfiddle.net/N7UNU/

提交回复
热议问题