<style type="text/css">
body {
background:url(imgs/test.jpg) no-repeat top center ;
}
</style>
<script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
var ImgW = ;
alert(ImgW);
});
</script> 请问如何获取body 的背景图片的宽度和高度值?xiexie
body {
background:url(imgs/test.jpg) no-repeat top center ;
}
</style>
<script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
var ImgW = ;
alert(ImgW);
});
</script> 请问如何获取body 的背景图片的宽度和高度值?xiexie
img.src="XXX.jpg";
alert(img.height);
alert(img.width);
$("body").width(); $("body").height();
背景图片要不是这样?
$("body").attr("background-img").width();$("body").attr("background-img").height();-------------------------上面两个都是不行的$(function(){
var kk = $("body").attr("background");//.width();
var img = new Image();
img.src=kk;//------这样宽高都是0,图片没有加载完成//alert(img);
//alert($(img).width());
//alert(img.width);
//alert(img.height);//------要这样img.onreadystatechange=function(){
alert("dd");
if (img.readyState=="complete") {
alert(["图片大小是:",img.width,img.height]);
}
}});
img.src="imgs/test.jpg.jpg"; //背景图片
alert(img.height); //图片高度
alert(img.width); //图片宽度
2. if (window.all) {
imgSrc = document.body.currentStyle["backgroundImage"];
}
else if (window.getComputedStyle) {
imgSrc = window.getComputedStyle(document.body, null)['backgroundImage']
}
2. if (window.document.all) {
imgSrc = document.body.currentStyle["backgroundImage"];
}
else if (window.getComputedStyle) {
imgSrc = window.getComputedStyle(document.body, null)['backgroundImage']
}