简体   繁体   English

背景图片下方的白色区域

[英]White area below background image

I'm trying to get a random image every refresh on the background of my page. 我试图在页面背景上每次刷新时获取随机图像。 It works with the script below. 它可以与以下脚本一起使用。 But if I've got simply too much content, the image doesn't expand to the bottom and shows a white area where the rest of the content continues. 但是,如果我仅拥有太多内容,则图像不会扩展到底部,而是显示白色区域,其余部分继续出现。 How do I fix this? 我该如何解决? I've searched and already found things like the vertical align, changing font size and stuff like that. 我搜索并已经找到诸如垂直对齐,更改字体大小之类的内容。 Also changed the backgroundPosition in the script to "center bottom" but that doesn't change anything. 还将脚本中的backgroundPosition更改为“底部中心”,但这并没有任何改变。 Any ideas? 有任何想法吗?

function randomBg() {
        var bgs = new Array();
        bgs.push("images/bg/bg1.jpg");
        bgs.push("images/bg/bg2.jpg");
        bgs.push("images/bg/bg3.jpg");
        bgs.push("images/bg/bg4.jpg");
        bgs.push("images/bg/bg5.jpg");
        bgs.push("images/bg/bg6.jpg");
        bgs.push("images/bg/bg7.jpg");
        bgs.push("images/bg/bg8.jpg");
        bgs.push("images/bg/bg9.jpg");
        bgs.push("images/bg/bg10.jpg");
        document.body.style.backgroundImage = "url(" + bgs[randomize(0, bgs.length-1)] + ")";
        document.body.style.backgroundSize = 'cover';
        document.body.style.backgroundRepeat = 'no-repeat';
        document.body.style.backgroundPosition = 'center';
    }

Remove background-position:center . 删除background-position:center The background-size:cover will "Scale the background image to be as large as possible so that the background area is completely covered by the background image. Some parts of the background image may not be in view within the background positioning area" background-size:cover将“将背景图像缩放到尽可能大的位置,以使背景区域完全被背景图像覆盖。背景图像的某些部分可能不在背景定位区域内”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM