每次加载更新新的背景图

html结构:

<div class="main"></div>

js:

function saveImg() {
  var imglens =10;
  if (typeof(Storage) !== "undefined") {
  if (localStorage.imgPathcount) {
  localStorage.imgPathcount = Number(localStorage.imgPathcount) + 1;
  $(".main").css("background-image", 'url(img/' + localStorage.imgPathcount + '.jpg)')
  if (localStorage.imgPathcount>imglens) {
  localStorage.imgPathcount =1;
  $(".main").css("background-image", 'url(img/' + localStorage.imgPathcount + '.jpg)')
  }
  } else {
  localStorage.imgPathcount = 1;
  $(".main").css("background-image", 'url(img/' + localStorage.imgPathcount + '.jpg)')
  }
   
  } else {
   
  }
  }
  saveImg(); 
posted @ 2019-08-05 21:15  星雨,恒奋斗,过客  阅读(168)  评论(0编辑  收藏  举报