尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
html+css基础:27、动画(基本使用/其他属性/动画复合属性/动画与过渡区别/动画案例)
动画的基本使用/其他属性/动画复合属性/动画与过渡区别/动画案例等Ⅰ、基本使用animation-name: wangyoudong2;/animation-duration: 3s;/animation-delay: 0.2s;其一、代码为其二、结果为Ⅱ、其他属性animation-timing-function: linear;/animation-iteration-count: infinite;/animation-direction: alternate;/animation-fill-mode: forwards;/animation-play-state: paused;其一、代码为其二、结果为Ⅲ、动画的复合属性animation: forwards 3s 0.5s alternate-reverse linear 2 athome;其一、代码为其二、结果为Ⅳ、动画与过渡的区别transition: 3s linear;/animation: athome 3s linear forwards;其一、代码为其二、结果为Ⅴ、动画案例animation: bike 1s steps(31) infinite;其一、代码为其二、结果为Ⅵ、小结Ⅰ、基本使用animation-name: wangyoudong2;/animation-duration: 3s;/animation-delay: 0.2s;其一、代码为!DOCTYPEhtmlhtmllangzh-CNheadmetacharsetUTF-8title01_基本使用/titlestyle.outer{width:1000px;height:100px;border:1px solid black;}/* 定义一个动画定义一组关键帧—— 第一种方式 */keyframeswangyoudong{/* 第一帧 */from{}/* 最后一帧 */to{transform:translate(900px);background-color:red;}}/* 定义一个动画定义一组关键帧—— 第二种方式 */keyframeswangyoudong2{/* 第一帧 */0%{}/* 29% { background-color: red; } *//* 48% { background-color: orange; } *//* 88% { background-color: yellow; } *//* 最后一帧 */100%{transform:translate(900px)rotate(360deg);background-color:purple;border-radius:50%;}}.inner{width:100px;height:100px;background-color:deepskyblue;/* 应用动画到元素 *//* 此时的 animation-name 属性表示要应用的动画名称 */animation-name:wangyoudong2;/* 动画持续的时间 *//* 此时的 animation-duration 属性表示动画的持续时间 */animation-duration:3s;/* 动画延迟时间 *//* 此时的 animation-delay 属性表示动画的延迟时间 */animation-delay:0.2s;}/style/headbodydivclassouterdivclassinner/div/div/body/html其二、结果为//一进入页面后的页面//动画执行过程// 最终结果Ⅱ、其他属性animation-timing-function: linear;/animation-iteration-count: infinite;/animation-direction: alternate;/animation-fill-mode: forwards;/animation-play-state: paused;其一、代码为!DOCTYPEhtmlhtmllangzh-CNheadmetacharsetUTF-8title02_其他属性/titlestyle.outer{width:1000px;height:100px;border:1px solid black;}keyframesathome{from{}to{transform:translate(900px)rotate(360deg);background-color:purple;border-radius:50%;}}.inner{width:100px;height:100px;background-color:deepskyblue;/* 应用动画到元素 */animation-name:athome;/* 动画持续的时间 */animation-duration:3s;/* 动画延迟时间 */animation-delay:0.2s;/* ********其他属性--start*********** *//* 设置动画的方式 *//* 此时的 animation-timing-function 属性表示动画的方式 */animation-timing-function:linear;/* 动画播放的次数 *//* 此时的 animation-iteration-count 属性表示动画播放的次数 */animation-iteration-count:infinite;/* 动画的方向 *//* 此时的 animation-direction 属性表示动画的方向 */animation-direction:alternate;/* 动画以外的状态不发生动画的时候在哪里 *//* 此时的 animation-fill-mode 属性表示动画以外的状态 *//* animation-fill-mode: forwards; */}.outer:hover .inner{/* 动画的播放状态 *//* 此时的 animation-play-state 属性表示动画的播放状态 */animation-play-state:paused;}/style/headbodydivclassouterdivclassinner/div/div/body/html其二、结果为//一进入页面后的页面// 该动画支持反复移动//hover之后动画暂停Ⅲ、动画的复合属性animation: forwards 3s 0.5s alternate-reverse linear 2 athome;其一、代码为!DOCTYPEhtmlhtmllangzh-CNheadmetacharsetUTF-8title03_动画的复合属性/titlestyle.outer{width:1000px;height:100px;border:1px solid black;}keyframesathome{from{}to{transform:translate(900px)rotate(360deg);background-color:purple;border-radius:50%;}}.inner{width:100px;height:100px;background-color:deepskyblue;/* 动画的复合属性 第一个属性值表示 animation-fill-mode 第二个属性值表示 animation-duration 第三个属性值表示 animation-delay 第四个属性值表示 animation-direction 第五个属性值表示 animation-timing-function 第六个属性值表示 animation-iteration-count 第七个属性值表示 animation-name */animation:forwards 3s 0.5s alternate-reverse linear 2 athome;}.outer:hover .inner{/* 动画的播放状态 *//* 此时的 animation-play-state 属性表示动画的播放状态 */animation-play-state:paused;}/style/headbodydivclassouterdivclassinner/div/div/body/html其二、结果为//一进入页面后的页面// 该动画支持反复移动(2s内)//hover之后动画暂停// 最终结果Ⅳ、动画与过渡的区别transition: 3s linear;/animation: athome 3s linear forwards;其一、代码为!DOCTYPEhtmlhtmllangzh-CNheadmetacharsetUTF-8title04_动画与过渡的区别/titlestyle.outer{width:1000px;height:200px;border:1px solid black;}.inner{width:100px;height:100px;}/* 用过渡实现inner1跑到右边去 */.inner1{background-color:orange;/* 过渡效果第一个属性值表示过渡的持续时间第二个属性值表示过渡的方式 */transition:3s linear;}.outer:hover .inner1{transform:translate(900px);}/* 用动画实现inner2跑到右边去 */keyframesathome{0%{}50%{background-color:red;border-radius:50%;box-shadow:0px 0px 20px black;}100%{transform:translate(900px);}}.inner2{background-color:green;/* 动画效果第一个属性值表示动画名称第二个属性值表示持续时间第三个属性值表示 timing-function第四个属性值表示 fill-mode */animation:athome 3s linear forwards;}/style/headbodydivclassouterdivclassinner inner1过渡/divdivclassinner inner2动画/div/div/body/html其二、结果为//一进入页面后的页面//hover之后过渡效果才开始而动画效果已结束// 最终结果Ⅴ、动画案例animation: bike 1s steps(31) infinite;其一、代码为!DOCTYPEhtmlhtmllangzh-CNheadmetacharsetUTF-8title05_动画案例/titlestylediv{width:130px;height:130px;background-image:url(../images/bike.png);margin:0 auto;margin-top:100px;/* 使用动画 第一个属性值表示动画名称第二个属性值表示持续时间第三个属性值表示 steps(31)第四个属性值表示 iteration-count 其中 steps(31) 表示动画的帧数31表示有31帧steps()表示每一帧的间隔时间是一样的 */animation:bike 1ssteps(31)infinite;}keyframesbike{from{}to{background-position:0px -4030px;}}/style/headbodydiv/div/body/html其二、结果为//一进入页面后的页面骑车的动态效果Ⅵ、小结其一、哪里有不对或不合适的地方还请大佬们多多指点和交流其二、若有转发或引用本文章内容请注明本博客地址(直接点击下面 url 跳转) https://blog.csdn.net/weixin_43405300,创作不易且行且珍惜其三、有兴趣的话可以多多关注这个专栏(Vue(Vue2Vue3)面试必备专栏)(直接点击下面 url 跳转)https://blog.csdn.net/weixin_43405300/category_11525646.html?spm1001.2014.3001.5482**其四、再有兴趣的话也可以多多关注这个专栏(Java)(直接点击下面 url 跳转)[https://blog.csdn.net/weixin_43405300/category_12654744.html?spm1001.2014.3001.5482](https://blog.csdn.net/weixin_43405300/category_12654744.htm
RELATED

相关推荐

如何在一分钟以内完成 3DGS 训练?LiteGS:面向 3D 高斯泼溅的系统算法高性能框架 计算机视觉技术原理

如何在一分钟以内完成 3DGS 训练?LiteGS:面向 3D 高斯泼溅的系统算法高性能框架 计算机视觉技术原理

如何在一分钟以内完成 3DGS 训练?LiteGS:面向 3D 高斯泼溅的系统算法高性能框架 计算机视觉技术原理 本博客由计算机视觉实践撰写,是面向技术从业者的一篇计算机视觉技术原理深度解读。本博客较长,建议收藏后分次阅读。 前言 3…

📅 2026/10/31 2:02:02
ROS 参数与配置:把“配置项“从代码里外置(六)

ROS 参数与配置:把“配置项“从代码里外置(六)

ROS 参数与配置:把"配置项"从代码里外置(六) 通用基础优先 第六篇|ROS 通识系列|Docker 实战一图读懂本文:参数本质 → ROS1/ROS2 架构差异 → 命令行四件套 → 代码声明与监听 → yaml 复现。 …

📅 2026/10/31 2:02:02
stm32F103C8T6标准库综合实验二感应灯具(RD03雷达)

stm32F103C8T6标准库综合实验二感应灯具(RD03雷达)

目录1.传感器准备工作2.redme3.实验项目核心部分3.1 模式菜单(自动模式-常亮模式-常灭模式)3.2 模式循环切换3.3 RD03雷达处理函数3.4 按键切换状态3.5 反射传感器切换模式1.传感器准备工作 2.redme /**********************************************************************…

📅 2026/10/31 2:02:02
MORE NEWS

更多资讯

📰

计算机整数表示:补码原理与编程实践

1. 整数在计算机中的表示基础计算机内部所有数据最终都以二进制形式存储和处理。整数作为最基本的数据类型之一,其表示方式直接影响着程序的正确性和性能。现代计算机系统通常采用补码(Twos complement)表示有符号整数,这种设计使…

📰

电-热-气-碳多能流耦合调度模型优化实践

1. 项目概述:电-热-气-碳多能流耦合调度模型最近在调试一个综合能源系统优化模型时,发现碳捕集电厂和需求响应这两个看似不相关的模块组合后产生了意想不到的协同效应。这个融合了电力、热力、天然气和碳元素的多能流调度模型,在实际电网调度…

📰

Selenium自动化测试实战:从原理到企业级应用

1. 项目概述:Web自动化测试的核心价值在当今快速迭代的Web开发环境中,手动测试已成为制约交付效率的瓶颈。我仍记得三年前参与的一个电商项目,每次版本更新都需要5人团队耗费整整3天进行全量回归测试。直到我们引入Selenium自动化测试框架&am…

📰

Windows下编译Nginx完整指南:MSVC+OpenSSL+PCRE+zlib静态链接实战

简介:本资源是面向Windows平台Nginx源码编译初学者与中级开发者的完整工具集,专为在Windows 10环境下使用Visual Studio 2017编译支持HTTP-FLV协议的Nginx 1.20.2定制版本而准备,有效解决Windows下缺少类Unix构建环境、依赖库缺失及Perl脚本执…

📰

AI如何优化跨境电商选品与物流成本控制

1. 项目概述:CaptainAI如何重构Ozon跨境电商运营去年冬天,一位在深圳做家居用品的跨境电商朋友向我吐槽:他在Ozon平台上前三个月亏了20万,主要原因竟是选品失误和物流成本失控。这让我意识到,传统"人工试错"…

📰

Oracle 11.2.0.1 补丁避坑:OPatch 报错、启动与回滚排查

简介:面向Oracle 11.2.0.1数据库运维人员和初中级DBA的一份补丁安装说明文档,聚焦老旧版本数据库在安全加固、稳定性维护和日常补丁管理中的实际需求。文档围绕安装前实例状态确认、OPatch工具准备、数字补丁包按序应用、补丁版本核验以及特殊异常处理思…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬