通过java脚本或JQuery获取背景图像大小

时间:2017-06-03 19:46:19

标签: javascript jquery html css

因为我需要给出一个恒定的宽度&高度到我的div取决于我的背景图像大小,我需要找出。 这里有很多解决这个问题的方法......

喜欢这里: How do I get background image size in jQuery?

这是我的代码



body{
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-attachment: fixed;
    background-position: center;
    background-image: url(./mybgimg.png);
}
#a{
    position: absolute;
    margin: auto;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 980px;
    max-height: 680px;
    background-image: url(../myImage.png);
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
}

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>sample</title>
</head>
<body>
<div class="container">
		<div id="a">
			<div >
					<!-- sth that should place exactly in this div depending on what size is my #a div ...    -->
			</div>	
		</div>
	</div>
</body>
</html>
&#13;
&#13;
&#13;

我如何使用#a id获得div的背景图片大小?

0 个答案:

没有答案