Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

สร้างเอฟเฟกต์ Fade Out Right Big ด้วย CSS Animation


เอฟเฟกต์ Fade Out Right Big

องค์ประกอบจางหายพร้อมเลื่อนไปทางขวาระยะไกล (2000px) เวอร์ชัน "Big" หมายถึงระยะทางการเคลื่อนที่มากกว่าปกติ

โค้ดตัวอย่างสมบูรณ์

<html>
<head>
  <style>
    .animated {
      background-image: url(/css/images/logo.png);
      background-repeat: no-repeat;
      background-position: left top;
      padding-top: 95px;
      margin-bottom: 60px;
      -webkit-animation-duration: 10s;
      animation-duration: 10s;
      -webkit-animation-fill-mode: both;
      animation-fill-mode: both;
    }

    @-webkit-keyframes fadeOutRightBig {
      0%   { opacity: 1; -webkit-transform: translateX(0); }
      100% { opacity: 0; -webkit-transform: translateX(2000px); }
    }
    @keyframes fadeOutRightBig {
      0%   { opacity: 1; transform: translateX(0); }
      100% { opacity: 0; transform: translateX(2000px); }
    }

    .fadeOutRightBig {
      -webkit-animation-name: fadeOutRightBig;
      animation-name: fadeOutRightBig;
    }
  </style>
</head>
<body>
  <div id="animated-example" class="animated fadeOutRightBig"></div>
  <button onclick="myFunction()">Reload page</button>
  <script>
    function myFunction() { location.reload(); }
  </script>
</body>
</html>

การวิเคราะห์

ขั้นตอนTransform XOpacityพฤติกรรม
0%01เริ่มต้นปกติ
100%+2000px (ขวาจาก)0บินไปขวาจนหาย

เปรียบเทียบ Fade Out แบบต่างๆ

เอฟเฟกต์ทิศทางระยะทาง
Fade Out Upขึ้น20px (เล็ก)
Fade Out Up Bigขึ้น2000px (ใหญ่)
Fade Out Rightขวา20px (เล็ก)
Fade Out Right Bigขวา2000px (ใหญ่)
Fade Out Down Bigลง2000px
Fade Out Left Bigซ้าย2000px