<span><strong><span>1.用js插入一张图片并控制图片宽高</span></strong></span>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
$(".bd").append("<div id='mainbg'/>");
$("#mainbg").append("<img id='im' src='a82a2e72e7af59296db0d63e3d2ecc5e!n1200.jpg' />");
recover();
$(window).resize(function(e) {
recover();
});
});
function recover(){
var winw = $(window).width();
var winh = $(window).height();
$("#im").attr({width:winw, height:winh});
}
</script>
利用CSS按比例缩放背景图片
<style type="text/css">
.bd{
background-image:url(a82a2e72e7af59296db0d63e3d2ecc5e!n1200.jpg);
background-repeat:no-repeat;
background-size:cover;
}
</style>
<body>
</body>
【页面背景图片的拉伸实现代码】相关文章: