繁体   English   中英

动画后无法在网页中移动文本

[英]cannot move text in webpage after it is animated

尝试制作页面时,我添加了animation-fill-mode: forwards 动画完成后,我无法将特定文本(动画)沿动画方向移动。 例如,如果我使用top动画,那么当我手动尝试移动文本(向上或向下)时,我将无法执行此操作。 左右都可以,但top不能。

 * @media screen and (max-width: 768px) {} @keyframes heading { from { top: 350px; } to { top: 300px; } } @keyframes quote { from { top: 290px } to { top: 240px } } @keyframes button { from { opacity: 0 } to { opacity: 1 } } @keyframes mvbut { from { top: 266px; right: 185px } to { top: 250px; right: 170px; } } .button { background-color: white; color: black; padding: 16px 32px; text-align: center; font-size: 16px; transition-duration: 0.4s; cursor: pointer; } .button1 { background-color: white; color: black; border: 1px solid white; position: relative; top: 266px; right: 185px; border-radius: 30px 7px; display: block; margin: auto; opacity: 0; animation-name: button; animation-duration: 0.5s; animation-delay: 2s; animation-fill-mode: forwards; } .button1:hover { background-color: black; color: white; } .button3:click { animation-name: mvbut; animation-duration: 1s; animation-fill-mode: forwards; } .button2 { background-color: white; color: black; border: 1px solid white; position: relative; top: 210px; left: 0px; border-radius: 30px 7px; display: block; margin: auto; opacity: 0; animation-name: button; animation-duration: 0.5s; animation-delay: 2.3s; animation-fill-mode: forwards; } .button2:hover { background-color: black; color: white; } .button3 { background-color: white; color: black; border: 1px solid white; position: relative; top: 154px; left: 185px; border-radius: 30px 7px; display: block; margin: auto; height: auto; opacity: 0; animation-name: button; animation-duration: 0.5s; animation-delay: 2.6s; animation-fill-mode: forwards; } .button3:hover { background-color: black; color: white; } @font-face { font-family: beatsurge; src: url(neutronium.ttf); } p.border { border-style: solid; border-width: 2px; padding: 20px; position: absolute; border-radius: 50px 20px; position: absolute; } body { background-image: url("background.jpg"); background-repeat: no-repeat; background-size: cover; } h1 { color: white; font-family: beatsurge; font-size: 100px; text-align: center; top: 350px; left: 0px; position: relative; animation-name: heading; animation-duration: 1s; animation-delay: 1s; animation-fill-mode: forwards; } p { font-size: 20px; text-align: center; color: white; position: relative; top: 290px; left: 0px; animation-name: quote; animation-duration: 1s; animation-delay: 1.25s; animation-fill-mode: forwards; } 
 <div> <h1><strong>BEAT SURGE</strong></h1> </div> <p> Where words fail, music speaks. </p> <button class="button button1">Remixes</button> <button class="button button2">Original Content</button> <button class="button button3">About Us</button> 

animation-fill-mode: forwards; 告诉它在完成动画时将动画的最终值用作CSS。 这是预期的行为。

您可能想要做animation-fill-mode: backwards告诉它完成后使用CSS,将初始CSS设置为最终值,然后将0%关键帧设置为实际的初始CSS。

 * @media screen and (max-width: 768px) {} @keyframes heading { 0% { top: 350px; } 100% { top: 300px; } } @keyframes quote { from { top: 290px } to { top: 240px } } @keyframes button { from { opacity: 0 } to { opacity: 1 } } @keyframes mvbut { from { top: 266px; right: 185px } to { top: 250px; right: 170px; } } .button { background-color: white; color: black; padding: 16px 32px; text-align: center; font-size: 16px; transition-duration: 0.4s; cursor: pointer; } .button1 { background-color: white; color: black; border: 1px solid white; position: relative; top: 266px; right: 185px; border-radius: 30px 7px; display: block; margin: auto; opacity: 0; animation-name: button; animation-duration: 0.5s; animation-delay: 2s; animation-fill-mode: forwards; } .button1:hover { background-color: black; color: white; } .button3:click { animation-name: mvbut; animation-duration: 1s; animation-fill-mode: forwards; } .button2 { background-color: white; color: black; border: 1px solid white; position: relative; top: 210px; left: 0px; border-radius: 30px 7px; display: block; margin: auto; opacity: 0; animation-name: button; animation-duration: 0.5s; animation-delay: 2.3s; animation-fill-mode: forwards; } .button2:hover { background-color: black; color: white; } .button3 { background-color: white; color: black; border: 1px solid white; position: relative; top: 154px; left: 185px; border-radius: 30px 7px; display: block; margin: auto; height: auto; opacity: 0; animation-name: button; animation-duration: 0.5s; animation-delay: 2.6s; animation-fill-mode: forwards; } .button3:hover { background-color: black; color: white; } @font-face { font-family: beatsurge; src: url(neutronium.ttf); } p.border { border-style: solid; border-width: 2px; padding: 20px; position: absolute; border-radius: 50px 20px; position: absolute; } body { background-image: url("background.jpg"); background-color: blue; background-repeat: no-repeat; background-size: cover; } h1 { color: white; font-family: beatsurge; font-size: 100px; text-align: center; top: 300px; left: 0px; position: relative; animation-name: heading; animation-duration: 1s; animation-delay: 1s; animation-fill-mode: backwards; } p { font-size: 20px; text-align: center; color: white; position: relative; top: 290px; left: 0px; animation-name: quote; animation-duration: 1s; animation-delay: 1.25s; animation-fill-mode: forwards; } 
 <div> <h1><strong>BEAT SURGE</strong></h1> </div> <p> Where words fail, music speaks. </p> <button class="button button1" onClick="document.querySelector('h1').style.top = '280px';">Remixes</button> <button class="button button2">Original Content</button> <button class="button button3">About Us</button> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM