首页 > 其他 > 详细

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

时间:2017-08-01 11:52:57      阅读:230      评论:0      收藏:0      [点我收藏+]
<!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是浏览器高度和宽度发生改变

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!