首页 > Web开发 > 详细

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

时间:2017-08-23 12:57:43      阅读:212      评论:0      收藏:0      [点我收藏+]
直接上代码:
<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实现刷新页面出现随机背景图

原文:http://www.cnblogs.com/ynxrsoft/p/7417533.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!