js实现刷新页面出现随机背景图

it2025-03-19  15

js实现刷新页面出现随机背景图

直接上代码:<script> var bodyBgs = []; bodyBgs[0] = "IMG/01.jpg"; bodyBgs[1] = "IMG/02.jpg"; bodyBgs[2] = "IMG/03.jpg"; bodyBgs[3] = "IMG/04.jpg"; bodyBgs[4] = "IMG/05.jpg"; var randomBgIndex = Math.round( Math.random() * 4 ); //输出随机的背景图 document.write('<style>body{background:url(' + bodyBgs[randomBgIndex] + ')top center no-repeat; background-size:cover;}</style>');</script>

转载于:https://www.cnblogs.com/luoliangfei/p/7499924.html

相关资源:Jquery刷新页面背景图片随机变换的实现方法
最新回复(0)