码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-09-10 01:17:44      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:背景图   style   直接   index   no-repeat   document   center   jpg   []   

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>

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

标签:背景图   style   直接   index   no-repeat   document   center   jpg   []   

原文地址:http://www.cnblogs.com/luoliangfei/p/7499924.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!