Javascript 动画背景不固定
嘿,伙计们,我正在为我的网站设计一个新的背景。我正试图让它更生动一些。我目前在这里工作: 正如您所看到的,当您向下滚动页面时,名为“background”的div不会保持“fixed”。。。我似乎无法使它保持固定 我的CSS如下所示:Javascript 动画背景不固定,javascript,jquery,html,css,jquery-plugins,Javascript,Jquery,Html,Css,Jquery Plugins,嘿,伙计们,我正在为我的网站设计一个新的背景。我正试图让它更生动一些。我目前在这里工作: 正如您所看到的,当您向下滚动页面时,名为“background”的div不会保持“fixed”。。。我似乎无法使它保持固定 我的CSS如下所示: body { background-color: #0a0a0a; color: #a2a2a2; font-family: Arial, Helvetica, sans-serif; font-size: 12px; li
body {
background-color: #0a0a0a;
color: #a2a2a2;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 1.4;
margin: 0;
padding: 0;
background-image: url(http://wow-x.com/board/images/blackevo4-pure/background.jpg);
background-repeat: no-repeat;
background-position: center top;
background-attachment:fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#background {
background: url(http://wow-x.com/board/images/blackevo4-pure/back1.jpg);
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
opacity:0.1;
z-index:-1;
}
#midground {
background: url(http://wow-x.com/board/images/blackevo4-pure/midground.png) repeat 20% 20%;
background-attachment:fixed;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index:-2;
height:100%;
width:100%;
}
#foreground {
background: url(http://wow-x.com/board/images/blackevo4-pure/foreground.png) repeat 90% 110%;
background-attachment:fixed;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index:-3;
height:100%;
width:100%;
}
如果您试图保持
#background
div固定,请将其位置从位置:绝对代码>至<代码>位置:固定代码>
将position
属性设置为absolute意味着元素将相对于其第一个定位的祖先进行定位。在您的例子中,这是主体本身,因此图像会随着页面一起滚动
将position
属性设置为fixed意味着元素将相对于窗口进行定位。因此,它的位置将独立于滚动位置。简单修复使用
position:fixed
到您的#背景如果您试图保持#背景
div固定,请将其位置从位置:绝对代码>至<代码>位置:固定代码>