Hướng dẫn what properties can you animate css? - những thuộc tính nào bạn có thể làm động css?

  • Tổng quan / Công nghệ web

    Tài liệu tham khảo công nghệ web cho các nhà phát triển

  • HTML

    Cấu trúc nội dung trên web

  • CSS

    Mã được sử dụng để mô tả kiểu tài liệu

  • JavaScript

    Ngôn ngữ kịch bản đa năng

  • HTTP

    Giao thức truyền tài nguyên web

  • API web

    Giao diện để xây dựng các ứng dụng web

  • Tiện ích mở rộng web

    Phát triển tiện ích mở rộng cho trình duyệt web

  • Công nghệ web

    Tài liệu tham khảo công nghệ web cho các nhà phát triển

  • Thử nó

    Thuộc tính cấu thành

    Cú pháp

    /* @keyframes duration | easing-function | delay |
    iteration-count | direction | fill-mode | play-state | name */
    animation: 3s ease-in 1s 2 reverse both paused slidein;
    
    /* @keyframes duration | easing-function | delay | name */
    animation: 3s linear 1s slidein;
    
    /* two animations */
    animation: 3s linear slidein, 3s ease-out 5s slideout;
    

    Thuộc tính animation được chỉ định là một hoặc nhiều hình ảnh động duy nhất, được phân tách bằng dấu phẩy.

    Mỗi hoạt hình riêng lẻ được chỉ định là:

    • không, một hoặc hai lần xuất hiện của giá trị <time>
    • không hoặc một lần xuất hiện của các giá trị sau:
      • <single-easing-function>
      • <single-animation-iteration-count>
      • animation = 
        <single-animation>#

        <single-animation> =
        <time> ||
        <easing-function> ||
        <time> ||
        <single-animation-iteration-count> ||
        <single-animation-direction> ||
        <single-animation-fill-mode> ||
        <single-animation-play-state> ||
        [ none | <keyframes-name> ]

        <easing-function> =
        linear |
        <linear-easing-function> |
        <cubic-bezier-easing-function> |
        <step-easing-function>

        <single-animation-iteration-count> =
        infinite |
        <number [0,∞]>

        <single-animation-direction> =
        normal |
        reverse |
        alternate |
        alternate-reverse

        <single-animation-fill-mode> =
        none |
        forwards |
        backwards |
        both

        <single-animation-play-state> =
        running |
        paused

        <keyframes-name> =
        <custom-ident> |
        <string>

        <linear-easing-function> =
        linear( <linear-stop-list> )

        <cubic-bezier-easing-function> =
        ease |
        ease-in |
        ease-out |
        ease-in-out |
        cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

        <step-easing-function> =
        step-start |
        step-end |
        steps( <integer> [, <step-position> ]? )

        <linear-stop-list> =
        [ <linear-stop> ]#

        <step-position> =
        jump-start |
        jump-end |
        jump-none |
        jump-both |
        start |
        end

        <linear-stop> =
        <number> &&
        <linear-stop-length>?

        <linear-stop-length> =
        <percentage>{1,2}

        0
      • animation = 
        <single-animation>#

        <single-animation> =
        <time> ||
        <easing-function> ||
        <time> ||
        <single-animation-iteration-count> ||
        <single-animation-direction> ||
        <single-animation-fill-mode> ||
        <single-animation-play-state> ||
        [ none | <keyframes-name> ]

        <easing-function> =
        linear |
        <linear-easing-function> |
        <cubic-bezier-easing-function> |
        <step-easing-function>

        <single-animation-iteration-count> =
        infinite |
        <number [0,∞]>

        <single-animation-direction> =
        normal |
        reverse |
        alternate |
        alternate-reverse

        <single-animation-fill-mode> =
        none |
        forwards |
        backwards |
        both

        <single-animation-play-state> =
        running |
        paused

        <keyframes-name> =
        <custom-ident> |
        <string>

        <linear-easing-function> =
        linear( <linear-stop-list> )

        <cubic-bezier-easing-function> =
        ease |
        ease-in |
        ease-out |
        ease-in-out |
        cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

        <step-easing-function> =
        step-start |
        step-end |
        steps( <integer> [, <step-position> ]? )

        <linear-stop-list> =
        [ <linear-stop> ]#

        <step-position> =
        jump-start |
        jump-end |
        jump-none |
        jump-both |
        start |
        end

        <linear-stop> =
        <number> &&
        <linear-stop-length>?

        <linear-stop-length> =
        <percentage>{1,2}

        1
      • animation = 
        <single-animation>#

        <single-animation> =
        <time> ||
        <easing-function> ||
        <time> ||
        <single-animation-iteration-count> ||
        <single-animation-direction> ||
        <single-animation-fill-mode> ||
        <single-animation-play-state> ||
        [ none | <keyframes-name> ]

        <easing-function> =
        linear |
        <linear-easing-function> |
        <cubic-bezier-easing-function> |
        <step-easing-function>

        <single-animation-iteration-count> =
        infinite |
        <number [0,∞]>

        <single-animation-direction> =
        normal |
        reverse |
        alternate |
        alternate-reverse

        <single-animation-fill-mode> =
        none |
        forwards |
        backwards |
        both

        <single-animation-play-state> =
        running |
        paused

        <keyframes-name> =
        <custom-ident> |
        <string>

        <linear-easing-function> =
        linear( <linear-stop-list> )

        <cubic-bezier-easing-function> =
        ease |
        ease-in |
        ease-out |
        ease-in-out |
        cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

        <step-easing-function> =
        step-start |
        step-end |
        steps( <integer> [, <step-position> ]? )

        <linear-stop-list> =
        [ <linear-stop> ]#

        <step-position> =
        jump-start |
        jump-end |
        jump-none |
        jump-both |
        start |
        end

        <linear-stop> =
        <number> &&
        <linear-stop-length>?

        <linear-stop-length> =
        <percentage>{1,2}

        2
    • một tên tùy chọn cho hoạt hình, có thể là
      animation = 
      <single-animation>#

      <single-animation> =
      <time> ||
      <easing-function> ||
      <time> ||
      <single-animation-iteration-count> ||
      <single-animation-direction> ||
      <single-animation-fill-mode> ||
      <single-animation-play-state> ||
      [ none | <keyframes-name> ]

      <easing-function> =
      linear |
      <linear-easing-function> |
      <cubic-bezier-easing-function> |
      <step-easing-function>

      <single-animation-iteration-count> =
      infinite |
      <number [0,∞]>

      <single-animation-direction> =
      normal |
      reverse |
      alternate |
      alternate-reverse

      <single-animation-fill-mode> =
      none |
      forwards |
      backwards |
      both

      <single-animation-play-state> =
      running |
      paused

      <keyframes-name> =
      <custom-ident> |
      <string>

      <linear-easing-function> =
      linear( <linear-stop-list> )

      <cubic-bezier-easing-function> =
      ease |
      ease-in |
      ease-out |
      ease-in-out |
      cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

      <step-easing-function> =
      step-start |
      step-end |
      steps( <integer> [, <step-position> ]? )

      <linear-stop-list> =
      [ <linear-stop> ]#

      <step-position> =
      jump-start |
      jump-end |
      jump-none |
      jump-both |
      start |
      end

      <linear-stop> =
      <number> &&
      <linear-stop-length>?

      <linear-stop-length> =
      <percentage>{1,2}

      3,
      animation = 
      <single-animation>#

      <single-animation> =
      <time> ||
      <easing-function> ||
      <time> ||
      <single-animation-iteration-count> ||
      <single-animation-direction> ||
      <single-animation-fill-mode> ||
      <single-animation-play-state> ||
      [ none | <keyframes-name> ]

      <easing-function> =
      linear |
      <linear-easing-function> |
      <cubic-bezier-easing-function> |
      <step-easing-function>

      <single-animation-iteration-count> =
      infinite |
      <number [0,∞]>

      <single-animation-direction> =
      normal |
      reverse |
      alternate |
      alternate-reverse

      <single-animation-fill-mode> =
      none |
      forwards |
      backwards |
      both

      <single-animation-play-state> =
      running |
      paused

      <keyframes-name> =
      <custom-ident> |
      <string>

      <linear-easing-function> =
      linear( <linear-stop-list> )

      <cubic-bezier-easing-function> =
      ease |
      ease-in |
      ease-out |
      ease-in-out |
      cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

      <step-easing-function> =
      step-start |
      step-end |
      steps( <integer> [, <step-position> ]? )

      <linear-stop-list> =
      [ <linear-stop> ]#

      <step-position> =
      jump-start |
      jump-end |
      jump-none |
      jump-both |
      start |
      end

      <linear-stop> =
      <number> &&
      <linear-stop-length>?

      <linear-stop-length> =
      <percentage>{1,2}

      4 hoặc
      animation = 
      <single-animation>#

      <single-animation> =
      <time> ||
      <easing-function> ||
      <time> ||
      <single-animation-iteration-count> ||
      <single-animation-direction> ||
      <single-animation-fill-mode> ||
      <single-animation-play-state> ||
      [ none | <keyframes-name> ]

      <easing-function> =
      linear |
      <linear-easing-function> |
      <cubic-bezier-easing-function> |
      <step-easing-function>

      <single-animation-iteration-count> =
      infinite |
      <number [0,∞]>

      <single-animation-direction> =
      normal |
      reverse |
      alternate |
      alternate-reverse

      <single-animation-fill-mode> =
      none |
      forwards |
      backwards |
      both

      <single-animation-play-state> =
      running |
      paused

      <keyframes-name> =
      <custom-ident> |
      <string>

      <linear-easing-function> =
      linear( <linear-stop-list> )

      <cubic-bezier-easing-function> =
      ease |
      ease-in |
      ease-out |
      ease-in-out |
      cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

      <step-easing-function> =
      step-start |
      step-end |
      steps( <integer> [, <step-position> ]? )

      <linear-stop-list> =
      [ <linear-stop> ]#

      <step-position> =
      jump-start |
      jump-end |
      jump-none |
      jump-both |
      start |
      end

      <linear-stop> =
      <number> &&
      <linear-stop-length>?

      <linear-stop-length> =
      <percentage>{1,2}

      5

    Giá trị

    <single-easing-function>

    Xác định loại chuyển tiếp. Giá trị phải là một trong những giá trị có sẵn trong

    animation = 
    <single-animation>#

    <single-animation> =
    <time> ||
    <easing-function> ||
    <time> ||
    <single-animation-iteration-count> ||
    <single-animation-direction> ||
    <single-animation-fill-mode> ||
    <single-animation-play-state> ||
    [ none | <keyframes-name> ]

    <easing-function> =
    linear |
    <linear-easing-function> |
    <cubic-bezier-easing-function> |
    <step-easing-function>

    <single-animation-iteration-count> =
    infinite |
    <number [0,∞]>

    <single-animation-direction> =
    normal |
    reverse |
    alternate |
    alternate-reverse

    <single-animation-fill-mode> =
    none |
    forwards |
    backwards |
    both

    <single-animation-play-state> =
    running |
    paused

    <keyframes-name> =
    <custom-ident> |
    <string>

    <linear-easing-function> =
    linear( <linear-stop-list> )

    <cubic-bezier-easing-function> =
    ease |
    ease-in |
    ease-out |
    ease-in-out |
    cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

    <step-easing-function> =
    step-start |
    step-end |
    steps( <integer> [, <step-position> ]? )

    <linear-stop-list> =
    [ <linear-stop> ]#

    <step-position> =
    jump-start |
    jump-end |
    jump-none |
    jump-both |
    start |
    end

    <linear-stop> =
    <number> &&
    <linear-stop-length>?

    <linear-stop-length> =
    <percentage>{1,2}

    7.

    <single-animation-iteration-count>

    Số lần hoạt hình được chơi. Giá trị phải là một trong những giá trị có sẵn trong

    animation = 
    <single-animation>#

    <single-animation> =
    <time> ||
    <easing-function> ||
    <time> ||
    <single-animation-iteration-count> ||
    <single-animation-direction> ||
    <single-animation-fill-mode> ||
    <single-animation-play-state> ||
    [ none | <keyframes-name> ]

    <easing-function> =
    linear |
    <linear-easing-function> |
    <cubic-bezier-easing-function> |
    <step-easing-function>

    <single-animation-iteration-count> =
    infinite |
    <number [0,∞]>

    <single-animation-direction> =
    normal |
    reverse |
    alternate |
    alternate-reverse

    <single-animation-fill-mode> =
    none |
    forwards |
    backwards |
    both

    <single-animation-play-state> =
    running |
    paused

    <keyframes-name> =
    <custom-ident> |
    <string>

    <linear-easing-function> =
    linear( <linear-stop-list> )

    <cubic-bezier-easing-function> =
    ease |
    ease-in |
    ease-out |
    ease-in-out |
    cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

    <step-easing-function> =
    step-start |
    step-end |
    steps( <integer> [, <step-position> ]? )

    <linear-stop-list> =
    [ <linear-stop> ]#

    <step-position> =
    jump-start |
    jump-end |
    jump-none |
    jump-both |
    start |
    end

    <linear-stop> =
    <number> &&
    <linear-stop-length>?

    <linear-stop-length> =
    <percentage>{1,2}

    9.

    animation = 
    <single-animation>#

    <single-animation> =
    <time> ||
    <easing-function> ||
    <time> ||
    <single-animation-iteration-count> ||
    <single-animation-direction> ||
    <single-animation-fill-mode> ||
    <single-animation-play-state> ||
    [ none | <keyframes-name> ]

    <easing-function> =
    linear |
    <linear-easing-function> |
    <cubic-bezier-easing-function> |
    <step-easing-function>

    <single-animation-iteration-count> =
    infinite |
    <number [0,∞]>

    <single-animation-direction> =
    normal |
    reverse |
    alternate |
    alternate-reverse

    <single-animation-fill-mode> =
    none |
    forwards |
    backwards |
    both

    <single-animation-play-state> =
    running |
    paused

    <keyframes-name> =
    <custom-ident> |
    <string>

    <linear-easing-function> =
    linear( <linear-stop-list> )

    <cubic-bezier-easing-function> =
    ease |
    ease-in |
    ease-out |
    ease-in-out |
    cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

    <step-easing-function> =
    step-start |
    step-end |
    steps( <integer> [, <step-position> ]? )

    <linear-stop-list> =
    [ <linear-stop> ]#

    <step-position> =
    jump-start |
    jump-end |
    jump-none |
    jump-both |
    start |
    end

    <linear-stop> =
    <number> &&
    <linear-stop-length>?

    <linear-stop-length> =
    <percentage>{1,2}

    0

    Hướng mà hoạt hình được chơi. Giá trị phải là một trong những giá trị có sẵn trong

    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    1.

    animation = 
    <single-animation>#

    <single-animation> =
    <time> ||
    <easing-function> ||
    <time> ||
    <single-animation-iteration-count> ||
    <single-animation-direction> ||
    <single-animation-fill-mode> ||
    <single-animation-play-state> ||
    [ none | <keyframes-name> ]

    <easing-function> =
    linear |
    <linear-easing-function> |
    <cubic-bezier-easing-function> |
    <step-easing-function>

    <single-animation-iteration-count> =
    infinite |
    <number [0,∞]>

    <single-animation-direction> =
    normal |
    reverse |
    alternate |
    alternate-reverse

    <single-animation-fill-mode> =
    none |
    forwards |
    backwards |
    both

    <single-animation-play-state> =
    running |
    paused

    <keyframes-name> =
    <custom-ident> |
    <string>

    <linear-easing-function> =
    linear( <linear-stop-list> )

    <cubic-bezier-easing-function> =
    ease |
    ease-in |
    ease-out |
    ease-in-out |
    cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

    <step-easing-function> =
    step-start |
    step-end |
    steps( <integer> [, <step-position> ]? )

    <linear-stop-list> =
    [ <linear-stop> ]#

    <step-position> =
    jump-start |
    jump-end |
    jump-none |
    jump-both |
    start |
    end

    <linear-stop> =
    <number> &&
    <linear-stop-length>?

    <linear-stop-length> =
    <percentage>{1,2}

    1

    Xác định cách áp dụng các kiểu cho mục tiêu của hoạt hình trước và sau khi thực hiện. Giá trị phải là một trong những giá trị có sẵn trong

    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    3.

    animation = 
    <single-animation>#

    <single-animation> =
    <time> ||
    <easing-function> ||
    <time> ||
    <single-animation-iteration-count> ||
    <single-animation-direction> ||
    <single-animation-fill-mode> ||
    <single-animation-play-state> ||
    [ none | <keyframes-name> ]

    <easing-function> =
    linear |
    <linear-easing-function> |
    <cubic-bezier-easing-function> |
    <step-easing-function>

    <single-animation-iteration-count> =
    infinite |
    <number [0,∞]>

    <single-animation-direction> =
    normal |
    reverse |
    alternate |
    alternate-reverse

    <single-animation-fill-mode> =
    none |
    forwards |
    backwards |
    both

    <single-animation-play-state> =
    running |
    paused

    <keyframes-name> =
    <custom-ident> |
    <string>

    <linear-easing-function> =
    linear( <linear-stop-list> )

    <cubic-bezier-easing-function> =
    ease |
    ease-in |
    ease-out |
    ease-in-out |
    cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

    <step-easing-function> =
    step-start |
    step-end |
    steps( <integer> [, <step-position> ]? )

    <linear-stop-list> =
    [ <linear-stop> ]#

    <step-position> =
    jump-start |
    jump-end |
    jump-none |
    jump-both |
    start |
    end

    <linear-stop> =
    <number> &&
    <linear-stop-length>?

    <linear-stop-length> =
    <percentage>{1,2}

    2

    Xác định xem hoạt hình có phát hay không. Giá trị phải là một trong những giá trị có sẵn trong

    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    5.

    Sự mô tả

    Thứ tự của các giá trị thời gian trong mỗi định nghĩa hoạt hình là quan trọng: giá trị thứ nhất có thể được phân tích cú pháp dưới dạng <time> được gán cho

    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    7 và giá trị thứ hai được gán cho
    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    8.

    Thứ tự của các giá trị khác trong mỗi định nghĩa hoạt hình cũng rất quan trọng để phân biệt giá trị

    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    9 với các giá trị khác. Nếu một giá trị trong tốc ký animation có thể được phân tích cú pháp làm giá trị cho thuộc tính hoạt hình khác với
    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    9, thì giá trị sẽ được áp dụng cho thuộc tính đó trước và không phải là
    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    9. Vì lý do này, thực tiễn được đề xuất là chỉ định giá trị cho
    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    9 là giá trị cuối cùng trong danh sách các giá trị khi sử dụng tốc ký animation; Điều này đúng ngay cả khi bạn chỉ định nhiều hình ảnh động được phân tách bằng dấu phẩy bằng cách sử dụng tốc ký animation.

    Giá trị

    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    9 không bắt buộc phải được khai báo trong tài sản tốc ký animation. Nếu không có tên tồn tại, không có hình ảnh động để áp dụng cho bất kỳ thuộc tính nào.

    Khi giá trị

    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    
    7 bị bỏ qua từ thuộc tính tốc ký animation, giá trị cho thuộc tính này mặc định là
    :root {
      overflow: hidden;
      background-color: lightblue;
      display: flex;
      justify-content: center;
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%;
      height: 100vh;
      aspect-ratio: 1 / 1;
      /* multiple animations are separated by commas */
      animation:
        4s linear 0s infinite alternate rise,
        /* animation parameters are set independently */
        24s linear 0s infinite psychedelic;
    }
    
    @keyframes rise {
      from {
        transform: translateY(110vh);
      }
      to {
        transform: translateY(0);
      }
    }
    
    @keyframes psychedelic {
      from {
        filter: hue-rotate(0deg);
      }
      to {
        filter: hue-rotate(360deg);
      }
    }
    
    0. Trong trường hợp này, hoạt hình vẫn sẽ xảy ra (các sự kiện
    :root {
      overflow: hidden;
      background-color: lightblue;
      display: flex;
      justify-content: center;
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%;
      height: 100vh;
      aspect-ratio: 1 / 1;
      /* multiple animations are separated by commas */
      animation:
        4s linear 0s infinite alternate rise,
        /* animation parameters are set independently */
        24s linear 0s infinite psychedelic;
    }
    
    @keyframes rise {
      from {
        transform: translateY(110vh);
      }
      to {
        transform: translateY(0);
      }
    }
    
    @keyframes psychedelic {
      from {
        filter: hue-rotate(0deg);
      }
      to {
        filter: hue-rotate(360deg);
      }
    }
    
    1 và
    :root {
      overflow: hidden;
      background-color: lightblue;
      display: flex;
      justify-content: center;
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%;
      height: 100vh;
      aspect-ratio: 1 / 1;
      /* multiple animations are separated by commas */
      animation:
        4s linear 0s infinite alternate rise,
        /* animation parameters are set independently */
        24s linear 0s infinite psychedelic;
    }
    
    @keyframes rise {
      from {
        transform: translateY(110vh);
      }
      to {
        transform: translateY(0);
      }
    }
    
    @keyframes psychedelic {
      from {
        filter: hue-rotate(0deg);
      }
      to {
        filter: hue-rotate(360deg);
      }
    }
    
    2 sẽ được bắn) nhưng sẽ không có hình ảnh động nào được hiển thị.

    Mối quan tâm tiếp cận

    Hoạt hình nhấp nháy và nhấp nháy có thể là vấn đề đối với những người có mối quan tâm nhận thức như rối loạn tăng động giảm chú ý (ADHD). Ngoài ra, một số loại chuyển động nhất định có thể là một kích hoạt cho các rối loạn tiền đình, bệnh động kinh và đau nửa đầu và scotopic.

    Cân nhắc việc cung cấp một cơ chế để tạm dừng hoặc vô hiệu hóa hoạt hình cũng như sử dụng truy vấn phương tiện chuyển động giảm để tạo trải nghiệm miễn phí cho người dùng đã thể hiện sở thích giảm trải nghiệm hoạt hình.

    • Thiết kế hoạt hình web an toàn hơn cho độ nhạy chuyển động
    • Giới thiệu về truy vấn truyền thông chuyển động giảm | CSS-tricks
    • Thiết kế đáp ứng cho chuyển động | Webkit
    • MDN Hiểu WCAG, Hướng dẫn 2.2 Giải thích
    • Hiểu tiêu chí thành công 2.2.2 | W3C Hiểu WCAG 2.0

    Định nghĩa chính thức

    Cú pháp chính thức

    animation = 
    <single-animation>#

    <single-animation> =
    <time> ||
    <easing-function> ||
    <time> ||
    <single-animation-iteration-count> ||
    <single-animation-direction> ||
    <single-animation-fill-mode> ||
    <single-animation-play-state> ||
    [ none | <keyframes-name> ]

    <easing-function> =
    linear |
    <linear-easing-function> |
    <cubic-bezier-easing-function> |
    <step-easing-function>

    <single-animation-iteration-count> =
    infinite |
    <number [0,∞]>

    <single-animation-direction> =
    normal |
    reverse |
    alternate |
    alternate-reverse

    <single-animation-fill-mode> =
    none |
    forwards |
    backwards |
    both

    <single-animation-play-state> =
    running |
    paused

    <keyframes-name> =
    <custom-ident> |
    <string>

    <linear-easing-function> =
    linear( <linear-stop-list> )

    <cubic-bezier-easing-function> =
    ease |
    ease-in |
    ease-out |
    ease-in-out |
    cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

    <step-easing-function> =
    step-start |
    step-end |
    steps( <integer> [, <step-position> ]? )

    <linear-stop-list> =
    [ <linear-stop> ]#

    <step-position> =
    jump-start |
    jump-end |
    jump-none |
    jump-both |
    start |
    end

    <linear-stop> =
    <number> &&
    <linear-stop-length>?

    <linear-stop-length> =
    <percentage>{1,2}

    Ví dụ

    Lưu ý: Hoạt hình các thuộc tính mô hình hộp CSS không được khuyến khích. Hoạt hình bất kỳ thuộc tính mô hình hộp nào vốn dĩ là CPU chuyên sâu; Xem xét hoạt hình thuộc tính chuyển đổi thay thế. Animating CSS Box Model properties is discouraged. Animating any box model property is inherently CPU intensive; consider animating the transform property instead.

    Bình Minh

    Ở đây chúng tôi làm động một mặt trời màu vàng trên bầu trời xanh nhạt. Mặt trời mọc lên trung tâm của khung nhìn và sau đó rơi ra khỏi tầm mắt.

    :root {
      overflow: hidden; /* hides any part of the sun below the horizon */
      background-color: lightblue;
      display: flex;
      justify-content: center; /* centers the sun in the background */
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%; /* creates a circular background */
      height: 100vh; /* makes the sun the size of the viewport */
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate sun-rise;
    }
    
    @keyframes sun-rise {
      from {
        /* pushes the sun down past the viewport */
        transform: translateY(110vh);
      }
      to {
        /* returns the sun to its default position */
        transform: translateY(0);
      }
    }
    

    Hoạt hình nhiều thuộc tính

    Thêm vào hoạt hình mặt trời trong ví dụ trước, chúng tôi thêm một hình ảnh động thứ hai thay đổi màu của mặt trời khi nó mọc và thiết lập. Mặt trời bắt đầu màu đỏ sẫm khi nó ở dưới đường chân trời và thay đổi thành màu cam sáng khi nó lên đến đỉnh.

    :root {
      overflow: hidden;
      background-color: lightblue;
      display: flex;
      justify-content: center;
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%;
      height: 100vh;
      aspect-ratio: 1 / 1;
      animation: 4s linear 0s infinite alternate animating-multiple-properties;
    }
    
    /* it is possible to animate multiple properties in a single animation */
    @keyframes animating-multiple-properties {
      from {
        transform: translateY(110vh);
        background-color: red;
        filter: brightness(75%);
      }
      to {
        transform: translateY(0);
        background-color: orange;
        /* unset properties i.e. 'filter' will revert to default values */
      }
    }
    

    Áp dụng nhiều hình ảnh động

    Đây là một mặt trời mọc và rơi trên nền sáng. Mặt trời dần quay qua cầu vồng màu sắc. Thời gian của vị trí và màu sắc của mặt trời là độc lập.

    :root {
      overflow: hidden;
      background-color: lightblue;
      display: flex;
      justify-content: center;
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%;
      height: 100vh;
      aspect-ratio: 1 / 1;
      /* multiple animations are separated by commas */
      animation:
        4s linear 0s infinite alternate rise,
        /* animation parameters are set independently */
        24s linear 0s infinite psychedelic;
    }
    
    @keyframes rise {
      from {
        transform: translateY(110vh);
      }
      to {
        transform: translateY(0);
      }
    }
    
    @keyframes psychedelic {
      from {
        filter: hue-rotate(0deg);
      }
      to {
        filter: hue-rotate(360deg);
      }
    }
    

    Xếp tầng nhiều hình ảnh động

    Đây là một mặt trời màu vàng trên nền đèn chiếu sáng. Mặt trời nảy giữa bên trái và bên phải của khung nhìn. Mặt trời vẫn còn trong chế độ xem mặc dù hoạt hình tăng được xác định. Thuộc tính chuyển đổi của Rise Animation bị 'ghi đè' bởi hình ảnh động nảy.

    :root {
      overflow: hidden;
      background-color: lightblue;
      display: flex;
      justify-content: center;
    }
    
    .sun {
      background-color: yellow;
      border-radius: 50%;
      height: 100vh;
      aspect-ratio: 1 / 1;
      /*
        animations declared later in the cascade will override the
        properties of previously declared animations
      */
      animation:
        4s linear 0s infinite alternate rise,
        /* bounce 'overwrites' the transform set by rise */
        4s linear 0s infinite alternate bounce;
        /* hence the sun only moves horizontally */
    }
    
    @keyframes rise {
      from {
        transform: translateY(110vh);
      }
      to {
        transform: translateY(0);
      }
    }
    
    @keyframes bounce {
      from {
        transform: translateX(-50vw);
      }
      to {
        transform: translateX(50vw);
      }
    }
    

    Xem bằng cách sử dụng hình ảnh động CSS để biết các ví dụ bổ sung.

    Thông số kỹ thuật

    Sự chỉ rõ
    Hoạt hình CSS Cấp 1 # Hoạt hình
    # animation

    Tính tương thích của trình duyệt web

    Bảng BCD chỉ tải trong trình duyệt

    Xem thêm

    Những thuộc tính CSS nào có thể là hoạt hình?

    Một số thuộc tính CSS có thể được hoạt hình bằng cách sử dụng hoạt hình CSS hoặc chuyển tiếp CSS ...
    -moz-outline-radius..
    -moz-outline-radius-bottomleft..
    -moz-outline-radius-bottomright..
    -moz-outline-radius-topleft..
    -moz-outline-radius-topright..
    -ms-grid-columns..
    -ms-grid-rows..
    -webkit-line-clamp..

    Bạn có thể làm động CSS thuộc tính hiển thị không?

    Bạn cũng không thể sử dụng thuộc tính hiển thị trong hình ảnh động CSS. either.

    Thuộc tính CSS nào đặt ra một hoạt hình tiến triển như thế nào?

    Thuộc tính CSS thời gian hoạt hình đặt thời gian mà một hình ảnh động mất một chu kỳ.animation-duration CSS property sets the length of time that an animation takes to complete one cycle.

    Bạn có thể làm động bằng cách sử dụng CSS không?

    Hoạt hình CSS giúp có thể làm động các chuyển tiếp từ cấu hình kiểu CSS này sang cấu hình kiểu CSS khác.Hoạt hình bao gồm hai thành phần, một kiểu mô tả hoạt hình CSS và một bộ các khung chính biểu thị trạng thái khởi động và kết thúc của phong cách hoạt hình, cũng như các điểm trung gian có thể.. Animations consist of two components, a style describing the CSS animation and a set of keyframes that indicate the start and end states of the animation's style, as well as possible intermediate waypoints.