每次加载更新新的背景图
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(); |