JS脚本实现刷新页面,随机加载背景图片

新建switch.js,内容如下:

	var imgs = [
	           "https://mlabs.gitee.io/pics/webp/tiankong002-mid.webp",
	           "https://mlabs.gitee.io/pics/webp/wallhaven-gp1q87.webp",
	           "https://mlabs.gitee.io/pics/webp/shanshui007small.webp",
	           "https://mlabs.gitee.io/pics/webp/shenlin001-small.webp",
	           "https://mlabs.gitee.io/pics/webp/shanshui005-small.webp",
	           "https://mlabs.gitee.io/pics/webp/shanshui005-mid.webp",
	           "https://mlabs.gitee.io/pics/webp/shanshui004-small.webp",
	           "https://mlabs.gitee.io/pics/webp/shanshui003-samll.webp",
	           "https://mlabs.gitee.io/pics/webp/jianzhou001-small.webp",
	           "https://mlabs.gitee.io/pics/webp/wallhaven-exvvqk.webp",
	           "https://mlabs.gitee.io/pics/webp/tianyuan001-small.webp",
	           "https://mlabs.gitee.io/pics/webp/yuzhou001-small.webp",
	           ];
	var index=Math.floor(Math.random()*imgs.length);;
	var img = imgs[index];
    document.write("<BODY BACKGROUND="+img+"  no-repeat>");

新建switch.html,内容如下:

<!DOCTYPE html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>Switch</title>
	<script src="./switch.js"></script>
	<style>
        body {
	         background-color: #efefef;
             background-repeat: no-repeat; 
		     background-attachment: fixed; 
		     background-position: center 0; 
		     background-size: cover; 
    	}
     </style>
</head>
<body>
</body>
</html>
posted @   风之夭夭  阅读(334)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
点击右上角即可分享
微信分享提示