[英]How to set background size (height & width)?
I'm very new to JavaScript.我对 JavaScript 很陌生。
My code so far:到目前为止我的代码:
$("#Stage").css(
"background-image",
"url(BG.jpg)",
"background-attachment",
"fixed"
);
What I want to do is have the background image at a set size so lets say: width: 100%
and height: 100%
.我想要做的是将背景图像设置为固定大小,因此可以说: width: 100%
和height: 100%
。
You want to use background-size: 100%
.您想使用background-size: 100%
。 Ensure that its browser support is compatible with your supported platforms.确保其浏览器支持与您支持的平台兼容。
$("#Stage").css({
"background-image": "url(BG.jpg)",
"background-attachment": "fixed",
"background-size": "100%"
});
This worked for me (inside a slider):这对我有用(在滑块内):
<!-- CSS -->
<style>
div.img {
background-repeat: no-repeat;
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
div.img:nth-of-type(1) {background-image: url('img.jpg');}
div.img:nth-of-type(2) {background-image: url('img.jpg');
}
</style>
<!-- HTML -->
<div class="img"></div>
This is just simple CSS, not jQuery.这只是简单的 CSS,而不是 jQuery。 You can read more about background-size
here: http://www.w3schools.com/cssref/css3_pr_background-size.asp您可以在此处阅读有关background-size
更多信息: http : //www.w3schools.com/cssref/css3_pr_background-size.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.