1 回答
TA贡献1909条经验 获得超7个赞
真的吗 ?如果/否则如果!简单点...
const BgSize = [ '200% 100%', '100% 100%']
var indx = 0
document.getElementById('stopMotionIcon').onclick =_=>
{
indx = ++indx %2
document.body.style.backgroundSize = BgSize[indx]
}
body {
font-family: verdana, arial, sans-serif;
font-size: 14px;
margin: 0;
width: 100%;
height: 100vh;
text-align: center;
background: linear-gradient(to left, #24292C, grey, #99958B, #C2BDB3, #EAE7E1, #EAE7E1, #C2BDB3, #99958B, grey, #24292C);
background-size: 200% 100%;
animation: gradientBG 10s ease infinite;
}
@keyframes gradientBG {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
<header>
<button id="stopMotionIcon" >Stop Background Motion</button>
<h1>a</h1>
</header>
添加回答
举报