Advertisement
Aiixu

Fade between multiple images

Mar 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. Hello !
  2. I'm trying to make a website for a school project, and I would like to add some animations made with CSS.
  3. I found this code on internet :
  4.  
  5. ----------------------------------
  6. CSS
  7. #crossfade > img
  8. {
  9. width: 100%;
  10. height: 100%;
  11. position: absolute;
  12. top: 0px;
  13. left: 0px;
  14. color: transparent;
  15. opacity: 0;
  16. z-index: 0;
  17. -webkit-backface-visibility: hidden;
  18. -webkit-animation: imageAnimation 30s linear infinite 0s;
  19. -moz-animation: imageAnimation 30s linear infinite 0s;
  20. -o-animation: imageAnimation 30s linear infinite 0s;
  21. -ms-animation: imageAnimation 30s linear infinite 0s;
  22. animation: imageAnimation 30s linear infinite 0s;
  23. }
  24.  
  25. #crossfade > img:nth-child(2)
  26. {
  27. -webkit-animation-delay: 6s;
  28. -moz-animation-delay: 6s;
  29. -o-animation-delay: 6s;
  30. -ms-animation-delay: 6s;
  31. animation-delay: 6s;
  32. }
  33. #crossfade > img:nth-child(3)
  34. {
  35. -webkit-animation-delay: 12s;
  36. -moz-animation-delay: 12s;
  37. -o-animation-delay: 12s;
  38. -ms-animation-delay: 12s;
  39. animation-delay: 12s;
  40. }
  41. #crossfade > img:nth-child(4)
  42. {
  43. -webkit-animation-delay: 18s;
  44. -moz-animation-delay: 18s;
  45. -o-animation-delay: 18s;
  46. -ms-animation-delay: 18s;
  47. animation-delay: 18s;
  48. }
  49. #crossfade > img:nth-child(5)
  50. {
  51. -webkit-animation-delay: 24s;
  52. -moz-animation-delay: 24s;
  53. -o-animation-delay: 24s;
  54. -ms-animation-delay: 24s;
  55. animation-delay: 24s;
  56. }
  57.  
  58. @-webkit-keyframes imageAnimation
  59. {
  60. 0% { opacity: 0; -webkit-animation-timing-function: ease-in; }
  61. 8% { opacity: 1; -webkit-animation-timing-function: ease-out; }
  62. 17% { opacity: 1 }
  63. 25% { opacity: 0 }
  64. 100% { opacity: 0 }
  65. }
  66.  
  67. @-moz-keyframes imageAnimation
  68. {
  69. 0% { opacity: 0; -moz-animation-timing-function: ease-in; }
  70. 8% { opacity: 1; -moz-animation-timing-function: ease-out; }
  71. 17% { opacity: 1 }
  72. 25% { opacity: 0 }
  73. 100% { opacity: 0 }
  74. }
  75.  
  76. @-o-keyframes imageAnimation
  77. {
  78. 0% { opacity: 0; -o-animation-timing-function: ease-in; }
  79. 8% { opacity: 1; -o-animation-timing-function: ease-out; }
  80. 17% { opacity: 1 }
  81. 25% { opacity: 0 }
  82. 100% { opacity: 0 }
  83. }
  84.  
  85. @-ms-keyframes imageAnimation
  86. {
  87. 0% { opacity: 0; -ms-animation-timing-function: ease-in; }
  88. 8% { opacity: 1; -ms-animation-timing-function: ease-out; }
  89. 17% { opacity: 1 }
  90. 25% { opacity: 0 }
  91. 100% { opacity: 0 }
  92. }
  93.  
  94. @keyframes imageAnimation
  95. {
  96. 0% { opacity: 0; animation-timing-function: ease-in; }
  97. 8% { opacity: 1; animation-timing-function: ease-out; }
  98. 17% { opacity: 1 }
  99. 25% { opacity: 0 }
  100. 100% { opacity: 0 }
  101. }
  102. ----------------------------------
  103. HTML
  104. <div id="crossfade">
  105. <img src="http://farm6.staticflickr.com/5145/5576437826_940f2db110.jpg" alt="Image 1">
  106. <img src="http://farm4.staticflickr.com/3611/3463265789_586ce40aef.jpg" alt="Image 2">
  107. <img src="http://farm6.staticflickr.com/5263/5601183065_f88a48d599.jpg" alt="Image 3">
  108. <img src="http://farm2.staticflickr.com/1415/983021323_8eb2f92c01.jpg" alt="Image 1">
  109. <img src="http://farm1.staticflickr.com/168/397834706_6a46c6ada5.jpg" alt="Image 1">
  110. </div>
  111. ----------------------------------
  112.  
  113. It works, but we can see the background between two images.
  114. What I want is the exact same effect, but without the background.
  115. I tried to modify 25% { opacity: 0 } to 25% { opacity: 1 }, and it worked, but, after a cycle, it stopped to work.
  116.  
  117. Thanks for reading !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement