Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Background-image leaves white space on refresh

I am currently building a website and I have some trouble while showing it up in Chrome.

When the site is completely loaded, you scroll to some point and hit the refresh button. There will be white squares above the background-image, it looks like the picture in the background doesn´t get loaded completely.

I tried to reproduce this error and it has the same problem. The problem only comes up with Google Chrome

this is my Source Code for the reproduced Site:

<html>
    <head>
        <style>
            body {
                background-image: url(http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-royalty-free-photos-images-for-commecial-use-awesome/wallpaper-royalty-free-photo-image-awesome-277.jpg) !important ;
                background-repeat:no-repeat; background-attachment:fixed;
            }
        </style>
    </head>
    <body>

-- Just pasted some long text from wikipedia here --

    </body>
</html>

I also found the same problem on a website while searching the problem: http://css-tricks.com/examples/FullPageBackgroundImage/progressive.php

when you scroll to the bottom and hit refresh, the image doesn´t show up 100%. When you start scrolling it instantly loads completely.

EDIT: missing important fact: It seems this error only happens when there is a scrollbar on the site, and you are not refreshing at the top of it.

like image 884
DarthVader Avatar asked Sep 26 '14 07:09

DarthVader


2 Answers

Try this:

<style>
        body {
            background: url(http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-royalty-free-photos-images-for-commecial-use-awesome/wallpaper-royalty-free-photo-image-awesome-277.jpg) center no-repeat ;
            background-size: cover;
            -webkit-background-size: cover; //safari chrome
            -moz-background-size: cover; // firefox
            -o-background-size: cover;
        }
</style>
like image 112
Topr Avatar answered Sep 27 '22 02:09

Topr


This seems like a problem related to the browser and not your code. But a workaround would be loading the background again with a script.

<script type="text/javascript">
function loadBg() {
        document.body.style.backgroundImage="url('backgroundImage.jpg')";
    }
</script>

<body onload="loadBg()">

I wouldn't be too concerned about this error though.

like image 28
Edwin Avatar answered Sep 26 '22 02:09

Edwin