开发指导—利用 CSS 动画实现 HarmonyOS 动效(二)

news2024/10/6 20:25:21

注:本文内容分享转载自 HarmonyOS Developer 官网文档

点击查看《开发指导—利用CSS动画实现HarmonyOS动效(一)》

3. background-position 样式动画

通过改变 background-position 属性(第一个值为 X 轴的位置,第二个值为 Y 轴的位置)移动背景图片位置,若背景图位置超出组件则超出部分的背景图不显示。

<!-- xxx.hml --><div class="container">  <div class="content"></div>  <div class="content1"></div></div>

/* xxx.css */.container {  height: 100%;  background-color:#F1F3F5;  display: flex;  flex-direction: column;  justify-content: center;  align-items: center;  width: 100%;}.content{  width: 400px;  height: 400px;  /* 不建议图片长宽比为1:1 */  background-image: url('common/images/bg-tv.jpg');  background-size: 100%;  background-repeat: no-repeat;  animation: change 3s infinite;  border: 1px solid black;}.content1{  margin-top:50px;  width: 400px;  height: 400px;  background-image: url('common/images/bg-tv.jpg');  background-size: 50%;  background-repeat: no-repeat;  animation: change1 5s infinite;  border: 1px solid black;}/* 背景图片移动出组件 */@keyframes change{  0%{    background-position:0px top;  }  25%{    background-position:400px top;  }  50%{    background-position:0px top;  }  75%{    background-position:0px bottom;  }  100%{    background-position:0px top;  }}/* 背景图片在组件内移动 */@keyframes change1{  0%{    background-position:left top;  }  25%{    background-position:50% 50%;  }  50%{    background-position:right bottom;  }  100%{    background-position:left top;;  }}

说明

background-position 仅支持背景图片的移动,不支持背景颜色(background-color)。

4.  svg 动画

为 svg 组件添加动画效果。

属性样式动画

在 Svg 的子组件animate中,通过 attributeName 设置需要进行动效的属性,from 设置开始值,to 设置结束值。

<!-- xxx.hml --><div class="container">  <svg>    <text x="300" y="300" fill="blue">      Hello      <animate attributeName="font-size" from="30" to="60" dur="3s" repeatCount="indefinite">      </animate>      <animate attributeName="fill" from="red" to="blue" dur="3s" repeatCount="indefinite">      </animate>      <animate attributeName="opacity" from="1" to="0.3" dur="3s" repeatCount="indefinite">      </animate>    </text>    <text x="300" y="600" fill="blue">      World      <animate attributeName="font-size" from="30" to="60" values="30;80" dur="3s" repeatCount="indefinite">      </animate>      <animate attributeName="fill" from="red" to="blue"  dur="3s" repeatCount="indefinite">      </animate>      <animate attributeName="opacity" from="0.3" to="1" dur="3s" repeatCount="indefinite">      </animate>    </text>  </svg></div>

说明

在设置动画变化值时,如果已经设置了 values 属性,则 from 和 to 都失效。

路径动画

在 Svg 的子组件animateMotion中,通过 path 设置动画变化的路径。

<!-- xxx.hml --><div class="container">  <svg fill="white" width="800" height="900">    <path d="M300,200 h-150 a150 150 0 1 0 150 -150 z" fill="white" stroke="blue" stroke-width="5" >    </path>    <path fill="red" d="M-5,-5 L10,0 L-5,5 L0,0 Z"  >      <animateMotion dur="2000" repeatCount="indefinite" rotate="auto-reverse"path="M300,200 h-150 a150 150 0 1 0 150 -150 z">      </animateMotion>    </path>  </svg></div>

animateTransform 动画

在 Svg 的子组件animateTransform中,通过 attributeName 绑定 transform 属性,type 设置动画类型,from 设置开始值,to 设置结束值。

<!-- xxx.hml --><div class="container" style="">    <svg>        <line x1="90" y1="300" x2="90" y2="730" stroke-width="10" stroke="black" stroke-linecap="round">            <animateTransform attributeName="transform" attributeType="XML" type="translate"  dur="3s" values="0;30;10;30;20;30;25;30" keyTimes="0;0.3;0.5;0.7;0.8;0.9;1.0;1.1"                              fill="freeze">            </animateTransform>        </line>        <circle cx="500" cy="500" r="50" stroke-width="15" fill="red" stroke="#e70d0d">            <animateTransform attributeName="transform" attributeType="XML" type="rotate"  dur="3s" values="0;30;10;30;20;30;25;30" keyTimes="0;0.3;0.5;0.7;0.8;0.9;1.0;1.1" fill="freeze">            </animateTransform>            <animateTransform attributeName="transform" attributeType="XML" type="scale"  dur="6s" values="1;1;1.3" keyTimes="0;0.5;1" fill="freeze"></animateTransform>            <animateTransform attributeName="transform" attributeType="XML" type="translate"  dur="9s" values="0;0;300 7" keyTimes="0;0.6;0.9" fill="freeze"></animateTransform>        </circle>        <line x1="650" y1="300" x2="650" y2="600" stroke-width="20" stroke="blue" stroke-linecap="round">            <animateTransform attributeName="transform" attributeType="XML" type="translate"  dur="9s" values="0;0;0 800" keyTimes="0;0.6;1" fill="freeze"></animateTransform>        </line>    </svg></div>

/* xxx.css */.container {  flex-direction: column;  align-items: center;  width: 100%;  height: 100%;  background-color: #F1F3F5;}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/971409.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【mybatis-plus】多数据源切换[dynamic-datasource] 手动切换数据源

Springbootmybatis-plusdynamic-datasourceDruid 手动切换数据源 文章目录 Springbootmybatis-plusdynamic-datasourceDruid 手动切换数据源0.前言1. 多数据源核心类浅析1. 1. DynamicDataSourceContextHolder切换数据源核心类1.2. DynamicRoutingDataSource 2.基于核心类的理解…

楼兰图腾——树状数组

在完成了分配任务之后&#xff0c;西部 314 来到了楼兰古城的西部。 相传很久以前这片土地上(比楼兰古城还早)生活着两个部落&#xff0c;一个部落崇拜尖刀(V)&#xff0c;一个部落崇拜铁锹(∧)&#xff0c;他们分别用 V 和 ∧ 的形状来代表各自部落的图腾。 西部 314 在楼兰古…

面试中的时间管理:如何在有限时间内展示最大价值

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…

基于SSM的新能源汽车在线租赁系统

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;采用Vue技术开发 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#x…

Mysql 高阶语句

高阶语句 对 MySQL 数据库的查询&#xff0c;除了基本的查询外&#xff0c;有时候需要对查询的结果集进行处理&#xff1b; 例如只取 10 条数据、对查询结果进行排序或分组等&#xff0c;来获取想要有用的数据 无非还是对于MySQL —— 增、删、改、查 的操作 升降序 SELECT…

电压互感器倍频感应耐压试验方法

试验方法 升压设备的容器应足够&#xff0c; 试验前应确认高压升压等设备功能正常&#xff1b; 按上图接好线&#xff0c; 三倍频发生器、 高压器外壳必须可靠接地。 将三倍频电源发生装置的输出线与被试电压互感器的一组二次绕组接线端连接好&#xff08;如 a-n 端&#xff0…

人体呼吸存在传感器成品,毫米波雷达探测感知技术,引领智能家居新潮流

随着科技的不断进步和人们生活质量的提高&#xff0c;智能化家居逐渐成为一种时尚和生活方式。 人体存在传感器作为智能家居中的重要组成部分&#xff0c;能够实时监测环境中人体是否存在&#xff0c;为智能家居系统提供更加精准的控制和联动。 在这个充满创新的时代&#xf…

测试靶场bWAPP安装部署

bWAPP&#xff08;Buggy Web Application&#xff09;是一个用于学习和练习网络应用安全的漏洞测试平台。它是一个开源的虚拟机或Docker映像&#xff0c;旨在为安全研究人员、开发人员和学生提供一个实践和演示各种Web应用漏洞的环境。 bWAPP包含了许多已知的Web应用程序漏洞&…

PAT 1164 Good in C 测试点3,4

个人学习记录&#xff0c;代码难免不尽人意。 When your interviewer asks you to write “Hello World” using C, can you do as the following figure shows? Input Specification: Each input file contains one test case. For each case, the first part gives the 26 …

「解析」YOLOv5 classify分类模板

学习深度学习有些时间了&#xff0c;相信很多小伙伴都已经接触 图像分类、目标检测甚至图像分割(语义分割)等算法了&#xff0c;相信大部分小伙伴都是从分类入门&#xff0c;接触各式各样的 Backbone算法开启自己的炼丹之路。 但是炼丹并非全是 Backbone&#xff0c;更多的是各…

Redis——数据结构介绍

Redis是一个key-value的数据库&#xff0c;key一般是String类型&#xff0c;不过value的类型是多样的&#xff1a; String&#xff1a;hello wordHash&#xff1a;{name:"Jack",age:21}List&#xff1a;[A -> B -> C -> D]Set&#xff1a;{A,B,C}SortedSet…

盖子的c++小课堂——第二十二讲:2维dp

前言 大家好&#xff0c;我又来更新了&#xff0c;今天终于有时间了aaaaaaaa 破500粉了&#xff0c;我太高兴了哈哈哈哈哈哈&#xff08;别看IP地址&#xff0c;我去北京旅游回来了&#xff0c;他没改回来&#xff09;&#xff0c;然后我马上就成为创作者一年了&#xff0c;希…

航空货运站AAT EDI 解决方案

Asia Airfreight Terminal (AAT)是一个航空货运站&#xff0c;总部设在香港国际机场&#xff0c;是亚洲首屈一指的运输枢纽。 AAT旨在成为世界上最好的航空货运站&#xff0c;将围绕成本竞争力和服务效率&#xff0c;客户服务&#xff0c;创新和员工承诺的业务战略来构建。 | 业…

Gradle下载安装教程

1、Gradle 入门 1.1、Gradle 简介 Gradle 是一款Google 推出的基于 JVM、通用灵活的项目构建工具&#xff0c;支持 Maven&#xff0c;JCenter 多种第三方仓库;支持传递性依赖管理、废弃了繁杂的xml 文件&#xff0c;转而使用简洁的、支持多种语言(例如&#xff1a;java、groo…

grpc + springboot + mybatis-plus 动态配置数据源

前言 这是我在这个网站整理的笔记&#xff0c;关注我&#xff0c;接下来还会持续更新。 作者&#xff1a;神的孩子都在歌唱 grpc springboot mybatis-plus 动态配置数据源 一. 源码解析1.1 项目初始化1.2 接口请求时候 二. web应用三. grpc应用程序 一. 源码解析 1.1 项目初…

Logback日志记录只在控制台输出sql,未写入日志文件【解决】

原因&#xff1a;持久层框架对于Log接口实现方式不一样&#xff0c;日记记录的位置及展示方式也也不一样 mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # sql只会打印到控制台不会输出到日志文件种mybatis-plus:configuration:log-impl…

链路追踪Skywalking应用实战

目录 1 Skywalking应用2 agent下载3 agent应用3.1 应用名配置3.2 IDEA集成使用agent3.3 生产环境使用agent 4 Rocketbot4.1 Rocketbot-仪表盘4.2 Rocketbot-拓扑图4.3 追踪4.4 性能分析4.5 告警4.5.1 警告规则详解4.5.2 Webhook规则4.5.3 自定义Webhook消息接收 1 Skywalking应…

微服务·架构组件之服务注册与发现-Nacos

微服务组件架构之服务注册与发现之Nacos Nacos服务注册与发现流程 服务注册&#xff1a;Nacos 客户端会通过发送REST请求的方式向Nacos Server注册自己的服务&#xff0c;提供自身的元数据&#xff0c;比如ip地址、端口等信息。 Nacos Server接收到注册请求后&#xff0c;就会…

ChatGPT 案例实战趋势分析面积图制作

面积图使用HTML,JS,Echarts 来完成代码可以使用ChatGPT AIGC 来实现代码编写。 完整的代码复制如下: <!DOCTYPE html> <html> <head><meta charset="utf-8"><script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.2.2/echa…

EasyPOI处理excel、CSV导入导出

1 简介 使用POI在导出导出excel、导出csv、word时代码有点过于繁琐&#xff0c;好消息是近两年在开发市场上流行一种简化POI开发的类库&#xff1a;easyPOI。从名称上就能发现就是为了简化开发。 能干什么&#xff1f; Excel的快速导入导出,Excel模板导出,Word模板导出,可以…