自适应屏幕大小的背景图片

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body{
            background-image: url(123.jpg);
            background-repeat: no-repeat;
        }
    </style>
</head>
<body>
    <script>
        function init(){
            document.body.style.backgroundSize="100% "+document.documentElement.clientHeight+"px";
        }
        init();
        window.onresize = function(){
            init()
        }    
    </script>
</body>
</html>
document.documentElement.clientHeight指的是浏览器的可见高度
onresize是浏览器高度和宽度发生改变
原文地址:https://www.cnblogs.com/shuaihan/p/7267591.html