Jquery 背景尺寸:封面;财产
当背景图像改变时,我需要它覆盖身体。我使用的是Jquery 背景尺寸:封面;财产,jquery,css,background-size,Jquery,Css,Background Size,当背景图像改变时,我需要它覆盖身体。我使用的是背景尺寸:cover,但它似乎不起作用 body { position: relative; margin-top: 60px; background-color: #000; font-family: 'Roboto Slab', serif; background: url(https://i.ytimg.com/vi/lECC6eQhnZo/maxresdefault.jpg); background-re
背景尺寸:cover
,但它似乎不起作用
body {
position: relative;
margin-top: 60px;
background-color: #000;
font-family: 'Roboto Slab', serif;
background: url(https://i.ytimg.com/vi/lECC6eQhnZo/maxresdefault.jpg);
background-repeat: no-repeat;
background-position: center center;
background-atachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
transition: background 1s;
下面是更改图像的jQuery:
$("body").css("background", objects[newNum].img);
图像存储在一个数组(对象)中
代码笔:背景封面是正确的工作。默认车身高度:自动。车身使用最小高度:100vh。并将边距顶部更改为填充顶部
body {
min-height: 100vh;
padding-top: 60px;
}
背景封面是正确的作品。默认车身高度:自动。车身使用最小高度:100vh。并将边距顶部更改为填充顶部
body {
min-height: 100vh;
padding-top: 60px;
}
您需要将背景的用法更改为背景图像。因为它与背景大小冲突 因此,对于您的CSS,它将是:
body {
position: relative;
margin-top: 60px;
background-color: #000;
font-family: 'Roboto Slab', serif;
background-image: url(https://i.ytimg.com/vi/lECC6eQhnZo/maxresdefault.jpg);
background-repeat: no-repeat;
background-position: center center;
background-atachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
transition: background 1s;
对于您的JS,它应该是:
$("body").css("background-image", objects[newNum].img);
您需要将背景的用法更改为背景图像。因为它与背景大小冲突 因此,对于您的CSS,它将是:
body {
position: relative;
margin-top: 60px;
background-color: #000;
font-family: 'Roboto Slab', serif;
background-image: url(https://i.ytimg.com/vi/lECC6eQhnZo/maxresdefault.jpg);
background-repeat: no-repeat;
background-position: center center;
background-atachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
transition: background 1s;
对于您的JS,它应该是:
$("body").css("background-image", objects[newNum].img);
只是抬头一看
背景附件:已修复和背景大小:封面
彼此玩得不好!:(
关于冲突的方式和原因的详细解释如下:
编辑:还有你的背景附件:修复了拼写错误!:)请注意
背景附件:已修复和背景大小:封面
彼此玩得不好!:(
关于冲突的方式和原因的详细解释如下:
编辑:另外,您的背景附件:修复了拼写错误!:)更改代码笔上的背景附件,使其具有两个t,而不是一个t,这确实会使它按我认为您所希望的方式工作。您还可以将背景规则组合成速记,如:
background: #000 url(https://i.ytimg.com/vi/lECC6eQhnZo/maxresdefault.jpg) center center / cover no-repeat;
background-attachment: fixed;
将代码笔上的背景附件
更改为两个t而不是一个t确实可以让它按照我认为您想要的方式工作。您还可以将背景规则组合成速记,如:
background: #000 url(https://i.ytimg.com/vi/lECC6eQhnZo/maxresdefault.jpg) center center / cover no-repeat;
background-attachment: fixed;
谢谢就这么简单,谢谢!就这么简单。