seeway

导航

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>

posted on 2017-08-23 11:58  seeway  阅读(1203)  评论(0编辑  收藏  举报