这个一般用于会员登录页面。刷新一次变一次背景大图,代码如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> html{ height: 100%; } body { background-size: 100% 100%; background-repeat: no-repeat; height: 100%; } </style> </head> <body> </body> <script> let imgArr = ["https://iknow-base.cdn.bcebos.com/qixiqbpcbanner.jpg", "https://iknow-base.cdn.bcebos.com/%E9%BB%84%E5%9C%A3%E4%BE%9D%E7%89%A9%E6%96%99%2Fqb%E9%A1%B5%E8%BD%AE%E6%92%AD%E5%9B%BE%E9%BB%84%E5%9C%A3%E4%BE%9D270x170x2.jpg", "https://iknow-base.cdn.bcebos.com/trishafish%2F%E7%9F%A5%E9%81%93PC-QB-540-280.jpg"]; //图片数据 let num = 0; let setNum = localStorage.getItem("num"); if (setNum) { num = setNum } console.log(imgArr[num]); //日志 document.body.style.backgroundImage = "url(" + imgArr[num] + ")" if (num == imgArr.length - 1) { num = 0; } else { num++; } localStorage.setItem("num", num) </script> </html>