所以我想创建一个动画背景,但不更改背景大小,因为如果将背景大小更改为最大为100%,我的网站会出现问题。
我的网站会失去健康。
这在js中可解决?? 这是代码:
body {
width: 100wh;
height: 90vh;
color: #fff;
background: linear-gradient(-45deg, #EE7752, #E73C7E, #23A6D5, #23D5AB);
background-size: 400% 400%;
-webkit-animation: Gradient 15s ease infinite;
-moz-animation: Gradient 15s ease infinite;
animation: Gradient 15s ease infinite;
}
@-webkit-keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
@-moz-keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
@keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
h1,
h6 {
font-family: 'Open Sans';
font-weight: 300;
text-align: center;
position: absolute;
top: 45%;
right: 0;
left: 0;
<h1>Pure CSS3 Animated Gradient Background</h1>
答案 0 :(得分:0)
在要考虑翻译动画的地方使用伪元素代替
:
body {
margin: 0;
height: 100vh;
color: #fff;
position: relative;
z-index: -1;
overflow: hidden;
}
body:before {
content: "";
position: absolute;
left: 0;
top: 0;
width: 400%;
height: 400%;
background: linear-gradient(-45deg, #EE7752, #E73C7E, #23A6D5, #23D5AB);
animation: Gradient 5s ease infinite;
}
@keyframes Gradient {
0%,
100% {
transform: translate(0, 0);
}
50% {
transform: translate(-75%,-75%);
}
}