How to write onshow event using javascript/jquery?

后端 未结 4 959
温柔的废话
温柔的废话 2021-02-02 16:41

I have an anchor tag on my page, i want an event attached to it, which will fire when the display of this element change.

How can i write this event? and catch whenever

4条回答
  •  春和景丽
    2021-02-02 17:26

    You could also override jQuery's default show method:

    var orgShow = $.fn.show;
    $.fn.show = function()
    {
        $(this).trigger( 'myOnShowEvent' );
        orgShow.apply( this, arguments );
        return this;
    }
    

    Now just bind your code to the event:

    $('#foo').bind( "myOnShowEvent", function()
    {
        console.log( "SHOWN!" )
    });
    

提交回复
热议问题