search
HomeWeb Front-endHTML TutorialAnimation modules in HTML and CSS

This time I will bring you the animation module in HTML and CSS. What are the things to note when using the animation module in HTML and CSS? The following is a practical case, let’s take a look. 1. Animation module

1. Similarities and differences between transition and animation

1.1 Differences

Transition must be triggered manually to execute animation

Animation can be executed without human triggering


1.2 Similarities

Transitions and animations are both used to add animations to elements

Transitions and animations are both new to the system Some properties

Both transition and animation need to meet three elements to have animation effects

2 Three elements of animation

2.1 Tell the system which animation needs to be executed

2.2 Tell the system we need Create an animation named lnj yourself

2.3 Tell the system how long the animation lasts

p{             width: 100px;    
 height: 50px;  
 background-color: red;       
 /*1.告诉系统需要执行哪个动画*/   
 animation-name: lnj;       
 /*3.告诉系统动画持续的时长*/             
  animation-duration: 3s;       }        
 /*2.告诉系统我们需要自己创建一个名称叫做lnj的动画*/  
 @keyframes lnj {            
  from{                 margin-left: 0;           }             
  to{                 margin-left: 500px; }         
  }

2. Animation module - other attributes (Part 1)

  p {         
  width: 100px;         
  height: 50px;         
  background-color: red;         
  animation-name: sport;         
  animation-duration: 2s;         
  /*告诉系统多少秒之后开始执行动画*/         
  /*animation-delay: 2s;*/         
  /*告诉系统动画执行的速度*/         
  animation-timing-function: linear;         
  /*告诉系统动画需要执行几次*/         
  animation-iteration-count: 3;  
  //infinite : 无限的         
  /*告诉系统是否需要执行往返动画         
  取值:         normal, 默认的取值, 执行完一次之后回到起点继续执行下一次         
  alternate, 往返动画, 执行完一次之后往回执行下一次         
  */         animation-direction: alternate;     }     
  @keyframes sport {         
  from{             margin-left: 0;         }         
  to{             margin-left: 500px;         }     }     
  p:hover{         
  /*         告诉系统当前动画是否需要暂停         
  取值:         running: 执行动画,默认取值         
  paused: 暂停动画, 当动画执行时,鼠标hover到p上方时,动画停止,鼠标移开,则继续动画;         
  */         
  animation-play-state: paused;     }

3. Animation module - other attributes ( Next)

      .box2{             
      width: 200px;             
      height: 200px;             
      background-color: blue;             
      margin: 100px auto;             
      animation-name: myRotate;             
      animation-duration: 5s;             
      animation-delay: 2s;             
      /*             通过我们的观察, 动画是有一定的状态的            
       1.等待状态             2.执行状态             3.结束状态             */
      /*             animation-fill-mode作用:             指定动画等待状态和结束状态的样式 
                  取值:             none: 不做任何改变             
                  forwards: 让元素结束状态保持动画最后一帧的样式; 
                  //向前的            
       backwards: 让元素等待状态的时候显示动画第一帧的样式; 
                   // 向后的             
                   both: 让元素等待状态显示动画第一帧的样式, 让元素结束状态保持动画最后一帧的样式
      */             
      /*animation-fill-mode: backwards;*/             
      /*animation-fill-mode: forwards;*/             
      animation-fill-mode: both;         }         
      @keyframes myRotate {            
       0%{                 transform: rotate(10deg);             }             
       50%{                 transform: rotate(50deg);             }             
       100%{                 transform: rotate(70deg);             }        
        } 
      animation-fill-mode

4. Animation module - continuous writing

1. Animation module continuous writing format

animation: animation name animation duration animation movement speed delay time execution number of round-trip animation;


2. The abbreviation of animation module consecutive format

animation: animation name animation duration;


5. Cloud effect

<html lang="en"> <head>     
<meta charset="UTF-8">     <title>104-动画模块-云层效果</title>     <style>         
*{             margin: 0;             padding: 0;         }         
ul{             height: 400px;             background-color: skyblue;             
margin-top: 100px;             animation: change 5s linear 0s infinite alternate;            
 position: relative;             overflow: hidden; //让屏幕下方的滚动条隐藏掉         }      
    ul li{             list-style: none;             width: 400%;  
    //设置li的宽度为屏幕的四倍,移动最多的为屏幕宽度的三倍,为保证屏幕内一直有云朵,故多设置一个屏幕的宽度的云朵
        height: 100%;             position: absolute; 
        // 设置子绝父相后,三个li会重叠到一起             
        left: 0;             top: 0;         }         ul li:nth-child(1){             
        background-image: url("images/cloud_one.png");             
        animation: one 30s linear 0s infinite alternate;         }         
        ul li:nth-child(2){             background-image: url("images/cloud_two.png");             
        animation: two 30s linear 0s infinite alternate;         }         
        ul li:nth-child(3){             background-image: url("images/cloud_three.png");             
        animation: three 30s linear 0s infinite alternate;         }         
        @keyframes change {             
        from{                 background-color: skyblue;             }             
        to{                 background-color: black;             }         }         
        @keyframes one {            
         from{                 margin-left: 0;             }             
         to{                 margin-left: -100%;  
         //如果先往右移动,又出现屏幕上有一节没云朵的情况,故先往左移动;             
         }         }         
         @keyframes two {            
          from{                 margin-left: 0;             }             
          to{                 margin-left: -200%;
          //由于动画的时间都一样,但是运动的距离不一样,又由于都是线性速度,所以就会出现有点运动快,有的运动慢!
                       }         }         
         @keyframes three {             from{                 margin-left: 0;             }             
         to{                 margin-left: -300%;             }         }     
         </style> </head> <body> <ul>     <li></li>     <li></li>     <li></li> </ul> </body> </html>

6. Infinite scrolling

<html lang="en"> <head>     <meta charset="UTF-8">     <title>105-动画模块-无限滚动</title>     
<style>         *{             margin: 0;             padding: 0;         }        
 p{             width: 600px;             height: 188px;             border: 1px solid #000;           
   margin: 100px auto;             overflow: hidden;         }         ul{             width: 2000px; 
   //这个无限滚动原理就是ul做动画             
   height: 188px;             background-color: black;  
   //背景颜色黑色,当li的透明度为半透明时,li就会有黑色蒙版效果             
   animation: move 10s linear 0s infinite normal;                      
   //name 时间 速度 延时 无限重复 是否往返(normal代表不往返)
            }         
            ul li{             float: left;             list-style: none;             width: 300px;
                         height: 188px;             background-color: red;             
                         border: 1px solid #000;             box-sizing: border-box;         }
                                  ul:hover{             
                                  /*动画添加给谁, 就让谁停止*/ 
                                              animation-play-state: paused;         } 
                                                      ul:hover li{             opacity: 0.5; 
                                                      //当li的透明度为0.5时,就会看到父元素的背景颜色(黑色),就会有蒙版效果
                                                               }         
                                                               ul li:hover{             opacity: 1; 
                                                               //透明度为1,不透明,看不到父元素的背景色,故没有蒙版效果
                                  }         @keyframes move {             
                                  from{                 margin-left: 0;             }             
                                  to{                 margin-left: -1200px;
                                  //只需要移除屏幕4个li的宽度就可.   屏幕上就会显示第5.6两个li,这时,原本的动画就会恢复的原来的位置接着动画,实现了无线滚动效果             
                       }         }     </style> </head> <body> <p>     <ul>         
                       <li>![](images/banner1.png)</li>         <li>![](images/banner2.jpg)</li>        
                       <li>![](images/banner3.jpg)</li>         <li>![](images/banner4.jpg)</li>         
                       //把前两个li加在后面,起到过度效果;动画不会显得太生硬.         
                       <li>![](images/banner1.png)</li>         <li>![](images/banner2.jpg)</li>     
                       </ul> </p> </body> </html>

Believe it or not After reading the case in this article, you have mastered the method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

2D conversion module in HTML and CSS


What are the precautions for using H5 in enterprise development

The above is the detailed content of Animation modules in HTML and CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML超文本标记语言--超在那里?(文档分析)HTML超文本标记语言--超在那里?(文档分析)Aug 02, 2022 pm 06:04 PM

本篇文章带大家了解一下HTML(超文本标记语言),介绍一下HTML的本质,HTML文档的结构、HTML文档的基本标签和图像标签、列表、表格标签、媒体元素、表单,希望对大家有所帮助!

html和css算编程语言吗html和css算编程语言吗Sep 21, 2022 pm 04:09 PM

不算。html是一种用来告知浏览器如何组织页面的标记语言,而CSS是一种用来表现HTML或XML等文件样式的样式设计语言;html和css不具备很强的逻辑性和流程控制功能,缺乏灵活性,且html和css不能按照人类的设计对一件工作进行重复的循环,直至得到让人类满意的答案。

web前端笔试题库之HTML篇web前端笔试题库之HTML篇Apr 21, 2022 am 11:56 AM

总结了一些web前端面试(笔试)题分享给大家,本篇文章就先给大家分享HTML部分的笔试题(附答案),大家可以自己做做,看看能答对几个!

HTML5中画布标签是什么HTML5中画布标签是什么May 18, 2022 pm 04:55 PM

HTML5中画布标签是“<canvas>”。canvas标签用于图形的绘制,它只是一个矩形的图形容器,绘制图形必须通过脚本(通常是JavaScript)来完成;开发者可利用多种js方法来在canvas中绘制路径、盒、圆、字符以及添加图像等。

总结HTML中a标签的使用方法及跳转方式总结HTML中a标签的使用方法及跳转方式Aug 05, 2022 am 09:18 AM

本文给大家总结介绍a标签使用方法和跳转方式,希望对大家有所帮助!

html中document是什么html中document是什么Jun 17, 2022 pm 04:18 PM

在html中,document是文档对象的意思,代表浏览器窗口的文档;document对象是window对象的子对象,所以可通过“window.document”属性对其进行访问,每个载入浏览器的HTML文档都会成为Document对象。

html5废弃了哪个列表标签html5废弃了哪个列表标签Jun 01, 2022 pm 06:32 PM

html5废弃了dir列表标签。dir标签被用来定义目录列表,一般和li标签配合使用,在dir标签对中通过li标签来设置列表项,语法“<dir><li>列表项值</li>...</dir>”。HTML5已经不支持dir,可使用ul标签取代。

Html5怎么取消td边框Html5怎么取消td边框May 18, 2022 pm 06:57 PM

3种取消方法:1、给td元素添加“border:none”无边框样式即可,语法“td{border:none}”。2、给td元素添加“border:0”样式,语法“td{border:0;}”,将td边框的宽度设置为0即可。3、给td元素添加“border:transparent”样式,语法“td{border:transparent;}”,将td边框的颜色设置为透明即可。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor