jQuery bind event listener before another

后端 未结 6 1041
無奈伤痛
無奈伤痛 2020-12-13 21:00

Using the prettyPhoto plugin to open modal-style content containers, and trying to integrate with Google Analytics\' Event Tracking to track when videos get opened.

6条回答
  •  情话喂你
    2020-12-13 22:00

    I'm using Jonathan's preBind method, slightly modified, and it does the trick nicely.

    $.fn.preBind = function (type, data, fn) {
        this.each(function () {
            var $this = $(this);
    
            $this.bind(type, data, fn);
    
            var currentBindings = $this.data('events')[type];
            if ($.isArray(currentBindings)) {
                currentBindings.unshift(currentBindings.pop());
            }
        });
        return this;
    };
    

提交回复
热议问题