📜  背景图像加载延迟 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:54.896000             🧑  作者: Mango

代码示例1
function init() {
  var imgDefer = document.querySelectorAll('div[data-src]');
  var style = "background-image: url({url})";
  for (var i = 0; i < imgDefer.length; i++) {

    imgDefer[i].setAttribute('style', style.replace("{url}", imgDefer[i].getAttribute('data-src')));

  }
}

window.onload = init;