码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-08-01 12:48:12      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:lan   背景图片   背景   char   tle   round   res   图片   title   

<!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是浏览器高度和宽度发生改变

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

标签:lan   背景图片   背景   char   tle   round   res   图片   title   

原文地址:http://www.cnblogs.com/shuaihan/p/7267591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!