当前位置:网站首页>transform-origin属性详解
transform-origin属性详解
2022-07-07 03:22:00 【鹿蹊zz】
transform-origin用于设置动画的基点(中心点) , 适用于所有块级元素及某些内联元素。
必须配合transform使用 默认情况下,元素的动作参考点为元素盒子的中心
可以设置九个位置的值:水平方向: left center right
0 50% 100%
垂直方向: top center bottom
默认值:50% 50% ,相对于center center
两种写法 ,
eg:
transform-origin: left;
transform-origin:0;
语法:
transform-origin: x-axis y-axis z-axis;
属性值详解
<div class="outer">
<div class="inner"></div>
<div class="inner"></div>
</div>
1.默认值,以自身原点旋转45deg
.outer {
width: 100px;
height: 100px;
background-color: #6a5acd8c;
margin: 200px;
position: relative;
}
/* (1)默认值旋转,红色为基点 默认值为 transform-origin: 50% 50% 0;*/
.inner {
transform: rotate(45deg);
/* transform-origin: 50% 50% 0; */
width: 100%;
height: 100%;
background-color: #6a5acdeb;
}
.outer .inner:nth-child(2){
width: 5px;
height: 5px;
background-color: red;
transform: none;
position: absolute;
top: 50px;
left: 50px;
}
2.以顶部旋转180deg
.outer {
width: 100px;
height: 100px;
background-color: #6a5acd8c;
margin: 200px;
position: relative;
}
/* (2)以顶部旋转180deg */
.inner {
transform: rotate(180deg);
transform-origin: 50% 0;
width: 100%;
height: 100%;
background-color: #6a5acdeb;
}
.inner:nth-child(2) {
width: 5px;
height: 5px;
background-color: red;
transform: none;
position: absolute;
top: -2.5px;
left: 50px;
}
3.以右部旋转150deg
/* 以右部旋转150deg 红色为基点 */
.inner {
transform: rotate(150deg);
transform-origin: 100% 50%;
width: 100%;
height: 100%;
background-color: #6a5acdeb;
}
.inner:nth-child(2) {
width: 5px;
height: 5px;
background-color: red;
transform: none;
position: absolute;
top: 47.5px;
left: 97.5px;
}
4.左上角旋转20deg 红色为基点
.inner {
transform: rotate(-20deg);
transform-origin: 0 0;
width: 100%;
height: 100%;
background-color: #6a5acdeb;
}
.inner:nth-child(2) {
width: 5px;
height: 5px;
background-color: red;
transform: none;
position: absolute;
top: -2.5px;
left: -2.5px;
}
从以上例子中可以看出,属性值的所代表的偏移位置,了解各属性值所代表的偏移位置后可以很灵活得使元素按照某一基准点进行旋转。
边栏推荐
- MySql用户权限
- MYSQL binlog相关命令
- Libcurl returns curlcode description
- Precise space-time travel flow regulation system - ultra-high precision positioning system based on UWB
- Anr principle and Practice
- 联合索引ABC的几种索引利用情况
- How to share the same storage among multiple kubernetes clusters
- [explanation of JDBC and internal classes]
- Brand · consultation standardization
- Common function detect_ image/predict
猜你喜欢
How to model and simulate the target robot [mathematical / control significance]
Leetcode T1165: 日志分析
unity3d学习笔记
【NOI模拟赛】区域划分(结论,构造)
如何给目标机器人建模并仿真【数学/控制意义】
Big coffee gathering | nextarch foundation cloud development meetup is coming
Precise space-time travel flow regulation system - ultra-high precision positioning system based on UWB
Matlab tips (30) nonlinear fitting lsqcurefit
化工园区危化品企业安全风险智能化管控平台建设四大目标
IP address
随机推荐
MATLAB小技巧(30)非线性拟合 lsqcurefit
Advantages of using net core / why
如何给目标机器人建模并仿真【数学/控制意义】
Maze games based on JS
【mysqld】Can't create/write to file
MATLAB小技巧(29)多项式拟合 plotfit
Matlab tips (29) polynomial fitting plotfit
关于数据库数据转移的问题,求各位解答下
场馆怎么做体育培训?
How Oracle backs up indexes
linux系统rpm方式安装的mysql启动失败
工具类:对象转map 驼峰转下划线 下划线转驼峰
Prime partner of Huawei machine test questions
[Luogu p1971] rabbit and egg game (bipartite game)
Four goals for the construction of intelligent safety risk management and control platform for hazardous chemical enterprises in Chemical Industry Park
Basic introduction of JWT
选择商品属性弹框从底部弹出动画效果
Big coffee gathering | nextarch foundation cloud development meetup is coming
健身房如何提高竞争力?
MySQL view bin log and recover data