html 如何过渡后,悬停关闭,其中动画是用于悬停

q9rjltbz  于 2023-11-15  发布在  其他
关注(0)|答案(1)|浏览(158)

我动画文本从0到100px在X轴内的一个div悬停。问题是当我悬停了div的动画快照回来非常快。我需要一个过渡效果看起来不错。请帮助我。谢谢
我尝试在div的正常状态和悬停状态下应用transition,但没有任何效果

dz6r00yl

dz6r00yl1#

你可以只在css中尝试,但建议使用JavaScript,因为当页面完全动画然后关闭时,悬停时正常工作,我强制宽度开始和结束于10px,否则你不能悬停在它上面。

  1. div.parent {
  2. display: block;
  3. width: 100%;
  4. height: 64px;
  5. }
  6. div.child {
  7. height: 64px;
  8. width: 10px;
  9. background: red;
  10. animation-name: htz; /* Default animation for non-hover state */
  11. animation-duration: 1s;
  12. animation-direction: normal;
  13. animation-iteration-count: 1;
  14. animation-fill-mode: forwards;
  15. }
  16. div.child:hover {
  17. animation-name: zth; /* Override animation for hover state */
  18. }
  19. @keyframes zth {
  20. from {
  21. width: 10px;
  22. }
  23. to {
  24. width: 100%;
  25. }
  26. }
  27. @keyframes htz {
  28. from {
  29. width: 100%;
  30. }
  31. to {
  32. width: 10px;
  33. }
  34. }

个字符

展开查看全部

相关问题