首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >背景图片修复设备大小phonegap

背景图片修复设备大小phonegap
EN

Stack Overflow用户
提问于 2013-03-21 19:00:02
回答 1查看 2.2K关注 0票数 0
代码语言:javascript
复制
1.Load image fix size of image

(function($) {
    $.fn.fullBg = function() {
        var bgImg = $(this);
        function resizeImg() {
            var imgwidth = bgImg.width();
            var imgheight = bgImg.height();

            var winwidth = $(window).width();
            var winheight = $(window).height();

            var widthratio = winwidth / imgwidth;
            var heightratio = winheight / imgheight;

            var widthdiff = heightratio * imgwidth;
            var heightdiff = widthratio * imgheight;

            if (heightdiff > winheight) {
                bgImg.css({
                    width : winwidth + 'px',
                    height : heightdiff + 'px'
                });
            } else {
                bgImg.css({
                    width : widthdiff + 'px',
                    height : winheight + 'px'
                });
            }
        }
        resizeImg();
        $(window).resize(function() {
            resizeImg();
        });
    };
})(jQuery)

2.index.html

代码语言:javascript
复制
<script type="text/javascript" charset="utf-8" src="js/main.js">
            $(window).load(function() {
                $("#background").fullBg();
            });
        </script>
    </head>
    <body>
        <img src="img/main_bg.png" alt="" id="background" />
        <div id="maincontent">
            <!-- Your site content goes here -->
        </div>
    </body>

3和css文件如下所示

代码语言:javascript
复制
 fullBg {
    position: fixed;
    top: 0;
    left: 0;
    overflow: hidden;
}

#maincontent {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 50;
}

这张图片是可滚动的,所以他们看到的都是空白。

提前感谢朋友们。欢迎大家提出任何想法,谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-03-21 19:45:58

尝试这个css背景属性,希望它能帮助你....

你的身体背景div css看起来像这样

代码语言:javascript
复制
<style type="text/css">
.backgroud {
    background:url(image.jpg) repeat;
    background-size: 100%;
}
</style>

html看起来像这样

代码语言:javascript
复制
<body>
    <div class="background">
        <div class="content"> -- Page Content --- </div>
    </div>
</body>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15545612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档