Image onload for static images

后端 未结 4 1510
轮回少年
轮回少年 2021-01-02 12:05

I know that for the image onload to work you have to set the src after the onload handler was attached. However I want to attach onload handlers to images that are static in

4条回答
  •  清酒与你
    2021-01-02 12:51

    Okay, I turned Borgars answer into a plugin, here it is:

    $.fn.imageLoad = function(fn){
        this.load(fn);
        this.each( function() {
            if ( this.complete && this.naturalWidth !== 0 ) {
                $(this).trigger('load');
            }
        });
    }
    

提交回复
热议问题