赞
踩
身为程序猿的我经常把transition、transform和translate这三者搞混,相信大多数程序猿也有同样的烦恼。既然如此我们就来探究探究。
先把这三者做一个简单解释:
div {
width: 100px;
height: 100px;
background-color: #f40;
position: absolute;
/* 变换 转换 移动 旋转 缩放 扭曲 */
/* transform: translate(0px) rotate(10deg) scale(2,1) skew(45deg); */
/* translate在指定的坐标轴上移动 */
/* transform: translateZ(100px) rotateY(30deg); */
/* 元素在父容器中居中,可以不用知道子容器的宽高 */
left: 50%;
transform: translateX(-50%);
}
div:hover {
transform: translate3d(100px, 100px, 50px);
}
transition 是一个复合属性
/* [属性名] [持续时间] [速度曲线] [延迟时间];*/
transition:transition-property transition-duration transition-timing-function transition-delay
transition: width 3s ease 1s;
transition: all 3s ease 1s;
注意:这里的所有属性是指能进行动画过渡的属性,有很多属性是不能进行过渡的,比如display,你不能让一个div的显示模式慢悠悠的发生过渡。
/*css:*/
div{
width:100px;
height:100px;
transition:all 1s;
}
//js
divEle.onclick = function(){
divEle.style.width = "200px";
divEle.style.height = "200px";
}
总结:transform是转换。transition是样式过渡。translate是移动,translate 是transform的属性值。
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。