Google AMP fly-in animation

 

The AMP HTML pages adding visual effect is easy using the amp-fx-collection component which provides a range of collections of effects such as fly-in which a background image can come into frame from any side of the screen this is a very popular and common effects that is seen in web pages nowadays.

Required Scripts: Importing the amp-fx-collection into the header

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script async custom-element="amp-fx-collection" src=
</script>

chevron_right


Attributes:



  1. data-duration: It specifies the duration of the animation it becomes static after the elapsed time.
  2. data-easing: Varies the animation speed throughout the entire duration.
  3. data-margin-start/end: Specifies at what % of margin of the viewport should the animation start.
  4. data-repeat: To repeat animation even after fully loaded after scroll.
  5. fly-in-bottom/top: Element flies in from the top or bottom.
  6. fly-in-left/right: Element flies in from the right or left.

Example:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!doctype html>
<html amp>
  
<head>
    <meta charset="utf-8">
    <title>Google AMP amp-fx-collection</title>
  
    <script async src=
    </script>
      
    <!-- Import `amp-fx-collection` extension in header -->
    <script async custom-element="amp-fx-collection" 
    </script>
  
    <link rel="canonical" href=
  
    <meta name="viewport" content=
"width=device-width,minimum-scale=1,initial-scale=1">
  
    <style amp-boilerplate>
        body {
            -webkit-animation: -amp-start 8s 
                steps(1, end) 0s 1 normal both;
              
            -moz-animation: -amp-start 8s 
                steps(1, end) 0s 1 normal both;
              
            -ms-animation: -amp-start 8s 
                steps(1, end) 0s 1 normal both;
              
            animation: -amp-start 8s 
                steps(1, end) 0s 1 normal both
        }
  
        @-webkit-keyframes -amp-start {
            from {
                visibility: hidden
            }
  
            to {
                visibility: visible
            }
        }
  
        @-moz-keyframes -amp-start {
            from {
                visibility: hidden
            }
  
            to {
                visibility: visible
            }
        }
  
        @-ms-keyframes -amp-start {
            from {
                visibility: hidden
            }
  
            to {
                visibility: visible
            }
        }
  
        @-o-keyframes -amp-start {
            from {
                visibility: hidden
            }
  
            to {
                visibility: visible
            }
        }
  
        @keyframes -amp-start {
            from {
                visibility: hidden
            }
  
            to {
                visibility: visible
            }
        }
    </style>
  
    <noscript>
        <style amp-boilerplate>
            body {
                -webkit-animation: none;
                -moz-animation: none;
                -ms-animation: none;
                animation: none
            }
        </style>
    </noscript>
  
    <style amp-custom>
        .header {
            position: relative;
            overflow: hidden;
        }
  
        .header h1 {
            color: white;
            bottom: 10%;
            left: 10px;
            position: absolute;
            z-index: 1;
            font-size: 1.7em;
        }
  
        .title {
            background-color: black;
            color: white;
        }
  
        .parallax-image-window {
            overflow: hidden;
        }
  
        .parallax-image-window amp-img {
            margin-bottom: -20%;
        }
    </style>
</head>
  
<body>
  
    <!--Scroll triggered fly-in animation 
        with default attributes -->
    <amp-img amp-fx="fly-in-left" 
        width="1600" height="900" 
        layout="responsive" src=
    </amp-img>
  
    <!-- Scroll triggered fly-in-bottom animation 
        with default attributes. -->
    <amp-img amp-fx="fly-in-bottom" 
        width="1600" height="900" 
        layout="responsive" src=
    </amp-img>
  
    <!--Fly in animation that lasts longer by 
        specifying `data-duration="2000ms"-->
    <amp-img amp-fx="fly-in-left" 
        data-duration="2000ms" 
        width="1280" height="873" 
        layout="responsive" src=
    </amp-img>
  
    <!-- Animation that takes place over 
        a larger distance by specifying 
        `data-fly-in-distance="50%"`.-->
    <amp-img amp-fx="fly-in-right" 
        data-fly-in-distance="50%" 
        width="1280" height="873" 
        layout="responsive" src=
    </amp-img>
</body>
  
</html>

chevron_right


Output: The image shown below is static. It has fly-in animations on each of them.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.