在線效果體驗:http://hovertree.com/texiao/mobile/3.htm
請使用手機浏覽器查看。
css代碼:
.bg{
background:url(http://hovertree.com/texiao/mobile/3/hovertree01.jpg);
filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')";
-moz-background-size:100% 100%;
background-size:100% 100%;
}
HTML文件代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>DIV縮放背景自適應(不變形)jQuery-HoverTree</title>
<style type="text/css">
a {
color: white;
}
body {
font-family: 幼圓,宋體,'Times New Roman', Times, serif;color:white;
}
.picwidth {
width: 100%;
text-align: left;
filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')";
-moz-background-size: 100% 100%;
background-size: 100% 100%;
}
body {
margin: 0px;
background-color: #120c0c;
}
.content {
width: 206px;
margin: 0px auto;
padding-top: 10px;
line-height: 16px;
}
.frame {
width: 256px;
margin: 0px auto;
}
</style>
<script src="http://hovertree.com/ziyuan/jquery/jquery-2.1.4.min.js"></script>
</head>
<body>
<div class="frame">
<div id="contentHead" style="height:231px;background-image:url(http://hovertree.com/texiao/mobile/3/hovertree01.jpg)" class="picwidth">
<input type="button" value="放大" id="keleyibig" /><input type="button" value="縮小" id="keleyismall" /><a href="http://hovertree.com/hvtart/bjae/f43r3qry.htm">原文</a>
</div>
<div id="contentBody" style="background-image:url(http://hovertree.com/texiao/mobile/3/hovertree02.jpg);height:99px;color:White;" class="picwidth">
<div class="content">
今日人物:
<div style="text-align:center">謝霆鋒</div>
<br />請點擊放大,縮小按鈕。
</div>
</div>
<div id="contentBottom" style="background-image:url(http://hovertree.com/texiao/mobile/3/hovertree03.jpg);height:124px" class="picwidth">DIV縮放背景自適應(不變形)
<br />請使用支持HTML5的浏覽器查看本頁
<br /><a href="http://hovertree.com/texiao/">特效庫</a> <a href="http://hovertree.com">首頁</a> <a href="http://"></a> <a href="http://hovertree.com/hvtart/bjae/f43r3qry.htm">原文</a></div>
</div>
<script>
$(function () {
$(".frame").width(300);
var documentWidth = $(document.body).width();
if (documentWidth < 600)
$(".frame").width(documentWidth);
var cHead = $("#contentHead"); var cBody = $("#contentBody"); var cBottom = $("#contentBottom");
function setHeight() {
cHead.height(((cHead.width() / 320) * 289));
cBody.height(((cBody.width() / 80) * 31));
cBottom.height(((cBottom.width() / 64) * 31));
}
setHeight();
$("#keleyibig").on("click", function ()
{
$(".frame").width($(".frame").width() + 50)
setHeight();
})
$("#keleyismall").on("click", function () {
$(".frame").width($(".frame").width() - 50)
setHeight();
})
})
</script>
</body>
</html>
這張圖可作為手機屏幕背景