Placeholder background/image while waiting for full image to load?

前端 未结 11 1617
栀梦
栀梦 2020-12-13 03:36

I have a few images on my page. I\'m finding that the page starts to render before the images have been loading (which is good), but that the visual effect is not great. Ini

11条回答
  •  情歌与酒
    2020-12-13 04:30

    Instead of referencing the image directly, stick it within a DIV, like the following:

    Then in your CSS:

    .placeholder {
        width: 300;
        height: 300;
        background-repeat: no-repeat;
        background-size: contain;
        background-image: url('my_placeholder.png');
    }
    

提交回复
热议问题