Attempting to trigger before & after events around jQuery show()

后端 未结 3 1810
攒了一身酷
攒了一身酷 2021-02-15 02:15

I\'m trying to get a piece of our JavaScript run after some 3rd party code makes a modal dialog appear. I saw a pretty neat idea of hijacking the jQuery show function, but unfor

3条回答
  •  囚心锁ツ
    2021-02-15 03:01

    I found another solution to this over here, with a slight tweak of my own.

    (function($){
        $.each(['show','hide'],function(i,ev){
            var el = $.fn[ev];              
            $.fn[ev] = function(){
                this.trigger(ev);
                return el.apply(this,arguments);
            };
        });                  
    })(jQuery);
    

    It doesn't offer the before/after events of other examples but it could certainly be elaborated on. It's working for me so far and hope it continues to do so--it's a nice little approach that can easily be expanded to other jQuery functions, including the various alternatives to show.

    ** Note this also fires an event for "hide".

提交回复
热议问题