当前位置:网站首页>Animate the box in the middle and 100px to the left and right of the browser
Animate the box in the middle and 100px to the left and right of the browser
2022-07-22 09:37:00 【Mom said that if the name is too long, hiding behind the tree w】
Let's do a simple animation today , Found that she did not know where to start , So write an article to say
error :
1. I don't know how to start
(1) You should know the status position and End state position
(2) You should know animation and Excessive first acquaintance and The end attribute is consistent
2. I don't know how to use a single attribute to make the box on the right
3. The initial and end attributes of the animation are inconsistent , The animation doesn't respond
Catalog
1. The box is vertically centered
2. The box is to the left of the browser 100px
3. Keep the box to the right of the browser 100px
Or add translation , Company % The width of is relative to itself
(3). Add left and right to the initial and end states of the animation
1. The box is vertically centered
Relative positioning of parent box , Sub box absolute positioning , From the top 50%
position: absolute;
top: 50%;
But the position is not centered , And half the height of the box , There are two ways
(1) Absolute positioning
according to calc( ) Dynamic computing
transform: translateY(-50%);
(2)transform: translateY
2D Translate half its height Company % The height of is relative to itself
transform: translateY(-50%);
(3)margin—— It is not recommended to use ( So don't write )
2. The box is to the left of the browser 100px
Relative positioning of parent box , Sub box absolute positioning , From the left 100px
(1) Absolute positioning
left: 100px;
(2)transform: translateX( It is inconvenient to calculate the right side only by translation )
3. Keep the box to the right of the browser 100px
Relative positioning of parent box , Sub box absolute positioning , To the right 100px
(1) Absolute positioning
But because of the initial state of the animation css attribute , And the initial state of the label css attribute , Consistent with the animation state end attribute
So there's no need to right
right: 100px;
according to calc( ) Dynamic computing First let the box run to the far right and subtract the box itself ( Width +100px)
left: calc(100% - 200px);
Or add translation , Company % The width of is relative to itself
left: calc(100% - 200px);
transform: translateX(-100%);
(3). Add left and right to the initial and end states of the animation
@keyframes move {
0% {
left: 100px;
background-color: darksalmon;
}
100% {
left: calc(100% - 200px);
background-color: dodgerblue;
}
}
All the code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
section {
width: 100%;
height: 900px;
background-color: lightblue;
position: relative;
}
.box {
width: 100px;
height: 100px;
background-color: pink;
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 100px;
animation: move 5s linear 0s infinite alternate forwards;
}
@keyframes move {
0% {
left: 100px;
background-color: darksalmon;
}
100% {
left: calc(100% - 200px);
background-color: dodgerblue;
}
}
</style>
</head>
<body>
<section>
<div class="box"></div>
</section>
</body>
</html>
边栏推荐
- 动画移动的相关规律(根据参数判断到底移动到哪里去)
- 嵌入式问题排查手段、网络问题、SD卡问题、设备启动问题、串口问题、i2c问题、spi问题、pcie等等问题
- 嵌入式之认识网卡phy自协商
- Geospatial matrix by province, city and county: multi index data sets such as prefecture level city space and geographical distance matrix
- 关于线程 thread (2)线程的使用简介
- High frequency leetcode deep search part: Sword finger offer 36 Binary search tree and bidirectional linked list
- 知识分享|分享一些提升企业文档管理水平的方法
- 数组的复制和数组地址值的复制
- Mvcc multi version concurrency control for MySQL learning
- 高频leetcode深搜部分:733. 图像渲染
猜你喜欢
SqlServer将数据库中的表复制到另一个数据库
数据治理质量保障研究
修改Hosts文件自定义本机IP域名
经验分享|企业该怎样利用SaaS进行企业知识管理
Mvcc multi version concurrency control for MySQL learning
Byte stream
Tens of millions of data: from 2000 to 2019, enterprise registration data longitude and latitude, registration number and other multi indicator information of provinces, cities and counties in China
flex布局的常用属性
Review background management system practice: two packaging styles of request parameters
Docker series VI Docker installation redis
随机推荐
SQL injection
refreshToken
EAS 审批流相关表
高频leetcode深搜部分:617. 合并二叉树
High frequency leetcode deep search part: 617 Merge binary tree
文字超出部分变成省略号的三种方式
flex布局的常用属性
贪吃蛇
Vector Foundation
Mvcc multi version concurrency control for MySQL learning
High frequency leetcode deep search part: 124 Maximum path sum in binary tree
EAS web BIM start access prompt 500 error
高频leetcode深搜部分:297. 二叉树的序列化与反序列化
Docker series 8 Mysql start slow query log under docker
1978-2021 China Statistical Yearbook, 2003-2019 (provincial and municipal panel data), 1999-2019 (county panel data)
Uni interceptor
响应式布局——视口viewport和常用单位
EAS BOS custom export (including excel style setting, multi tab export, export file directory verification and backup)
Gan objective function understanding
EAS版本升级后元数据发布报错