复制代码代码如下:
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><strong><span style="font-size:12px;color:#3333ff;">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 class="bd">
</body>