lazy load iframe (delay src http call) with jquery

后端 未结 6 2286
有刺的猬
有刺的猬 2020-12-05 05:13

I am looking for something similar to jQuery image lazy load plugin, but for iframes.

6条回答
  •  离开以前
    2020-12-05 06:03

    This worked for me.

    var iframes = $('iframe');
    
    $('button').click(function() {
        iframes.attr('src', function() {
            return $(this).data('src');
        });
    });
    
    iframes.attr('data-src', function() {
        var src = $(this).attr('src');
        $(this).removeAttr('src');
        return src;
    });
    

    jsFiddle.

提交回复
热议问题