doc_negative_animation.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <style>
  6. html, body {
  7. margin: 0;
  8. height: 100%;
  9. overflow: hidden;
  10. }
  11. div {
  12. position: absolute;
  13. top: 0;
  14. left: -500px;
  15. height: 20px;
  16. width: 500px;
  17. color: red;
  18. background: linear-gradient(to left, currentColor, currentColor 2px, transparent);
  19. }
  20. .zero {
  21. color: blue;
  22. top: 20px;
  23. }
  24. .positive {
  25. color: green;
  26. top: 40px;
  27. }
  28. .negative.move { animation: 5s -1s move linear forwards; }
  29. .zero.move { animation: 5s 0s move linear forwards; }
  30. .positive.move { animation: 5s 1s move linear forwards; }
  31. @keyframes move {
  32. to {
  33. transform: translateX(500px);
  34. }
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. <div class="negative"></div>
  40. <div class="zero"></div>
  41. <div class="positive"></div>
  42. <script>
  43. "use strict";
  44. var negative = document.querySelector(".negative");
  45. var zero = document.querySelector(".zero");
  46. var positive = document.querySelector(".positive");
  47. // The non-delayed animation starts now.
  48. zero.classList.add("move");
  49. // The negative-delayed animation starts in 1 second.
  50. setTimeout(function () {
  51. negative.classList.add("move");
  52. }, 1000);
  53. // The positive-delayed animation starts in 200 ms.
  54. setTimeout(function () {
  55. positive.classList.add("move");
  56. }, 200);
  57. </script>
  58. </body>
  59. </html>