We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
过渡动画,定义css初始样式开始到结束时候中间过度时间段内的动画效果,可称之为补间动画。
开始状态(动画放在这个状态里面) 结束状态(最终形态)
可以指定要进行过渡的css属性,如果提供多个属性值,以逗号进行分隔:
.style {transition-property: opacity, left, top, width;)
ease(逐渐变慢) 默认值 linear匀速 ease-in(加速) ease-out(减速) ease-in-out(先加速后减速 cubic-bezier贝塞尔曲线(x1,y1,x2,y2)
div { transition-property: width; transition-duration: 2s;/*过度时间2秒*/ transition-timing-function: ease; transition-delay: 2s;/*y延时2秒开始过度*/ }
为了书写方便,也可以把这四个属性按照以上顺序简写在一个 transition 属性上:
div { transition: width 2s ease 2s; }
如果使用属性的默认值,则可以省略:
div { transition: width 2s; /*相当于*/ /*transition: width 2s ease 0*/ }
使用transtion属性只是规定了要如何去过渡,要想让动画发生,还得要有元素状态的改变。如何改变元素状态呢,当然就是在css中给这个元素定义一个类(:hover等伪类也可以),这个类描述的是过渡动画结束时元素的状态。
<div>xiaoyueyue</div>
div { width: 200px; height: 200px; background-color: green; border-radius: 100px; text-align: center; line-height: 200px; color: #fff; font-weight: 700; transition: width 3s, height 3s, background-color 3s, opacity 3s; } div:hover { width: 100px; height: 100px; text-align: center; line-height: 100px; background-color: red; opacity: 0; }
还可以使用自定义类来实现
div { width: 200px; height: 200px; background-color: green; border-radius: 100px; text-align: center; line-height: 200px; color: #fff; font-weight: 700; transition: width 3s, height 3s, background-color 3s, opacity 3s; } div.on { width: 100px; height: 100px; text-align: center; line-height: 100px; background-color: red; opacity: 0; }
var box = document.querySelector('div'); box.onmouseenter = function () { box.classList.add('on'); }
Internet Explorer 10, Firefox, 和 Opera支持transform 属性.
Chrome 和 Safari 要求前缀 -webkit- 版本.
注意: Internet Explorer 9 要求前缀 -ms- 版本.
例子,直径为200的圆鼠标移入后向右移动100px同时颜色渐变为红色:
div { width: 200px; height: 200px; background-color: green; border-radius: 100px; text-align: center; line-height: 200px; color: #fff; font-weight: 700; transition: background-color 3s, transform 3s; } .on { transform: translate(100px); background: red; }
取值为眼睛距离图片的距离 600-1000px 是人眼最舒服的距离
设置有两种方式
给父元素设置
作为transform的属性写进transform里面
transform-style:preserve-3d; // 显示出3D效果
当在 @Keyframes 创建动画,把它绑定到一个选择器,否则动画不会有任何效果。
指定至少这两个CSS3的动画属性绑定向一个选择器:
关键帧的时间单位
数字:0%、25%、100%等
字符:from(0%)、to(100%)
例子:
@keyframes myfirst { 0% {background:red; left:0px; top:0px;} 25% {background:yellow; left:200px; top:0px;} 50% {background:blue; left:200px; top:200px;} 75% {background:green; left:0px; top:200px;} 100% {background:red; left:0px; top:0px;} } div { width:100px; height:100px; background:red; position:relative; animation-name:myfirst; animation-duration:5s; animation-timing-function:linear; animation-delay:2s; animation-iteration-count:infinite; animation-direction:alternate; animation-play-state:running; }
像前面讲的transition属性一样,也可以把这些animation属性简写到一个animation中,使用默认值的也可以省略掉。但 animation-play-state 属性不能简写到animation中
div { animation:myfirst 5s; }
注意,为了达到最佳的浏览器兼容效果,在实际书写代码的时候,还必须加上各大浏览器的私有前缀
当CSS 3的transition动画执行结束时,触发webkitTransitionEnd事件,使用:
dom.addEventListener(‘webkitTransitionEnd’,function(){})
添加cdn引用
<link href="https://cdn.bootcss.com/animate.css/3.5.2/animate.css" rel="stylesheet">
然后你想要哪个元素进行动画,就给那个元素添加上animated类 以及特定的动画类名,animated是每个要进行动画的元素都必须要添加的类。
animated
给上面的样式添加一个摇动的动画,因为摇动的动画类名为shake,所以代码是这样的:
shake
var box = document.querySelector('div'); box.onmouseenter = function () { box.classList.add('animated','shake'); }
至于动画的效果有差异可自定义样式进行覆盖
animation.css提供动画的可用class类名
bounce
flash
pulse
rubberBand
headShake
swing
tada
wobble
jello
bounceIn
bounceInDown
bounceInLeft
bounceInRight
bounceInUp
bounceOut
bounceOutDown
bounceOutLeft
bounceOutRight
bounceOutUp
fadeIn
fadeInDown
fadeInDownBig
fadeInLeft
fadeInLeftBig
fadeInRight
fadeInRightBig
fadeInUp
fadeInUpBig
fadeOut
fadeOutDown
fadeOutDownBig
fadeOutLeft
fadeOutLeftBig
fadeOutRight
fadeOutRightBig
fadeOutUp
fadeOutUpBig
flipInX
flipInY
flipOutX
flipOutY
lightSpeedIn
lightSpeedOut
rotateIn
rotateInDownLeft
rotateInDownRight
rotateInUpLeft
rotateInUpRight
rotateOut
rotateOutDownLeft
rotateOutDownRight
rotateOutUpLeft
rotateOutUpRight
hinge
jackInTheBox
rollIn
rollOut
zoomIn
zoomInDown
zoomInLeft
zoomInRight
zoomInUp
zoomOut
zoomOutDown
zoomOutLeft
zoomOutRight
zoomOutUp
slideInDown
slideInLeft
slideInRight
slideInUp
slideOutDown
slideOutLeft
slideOutRight
slideOutUp
The text was updated successfully, but these errors were encountered:
No branches or pull requests
transition
过渡动画,定义css初始样式开始到结束时候中间过度时间段内的动画效果,可称之为补间动画。
状态
开始状态(动画放在这个状态里面)
结束状态(最终形态)
参数
可以指定要进行过渡的css属性,如果提供多个属性值,以逗号进行分隔:
为了书写方便,也可以把这四个属性按照以上顺序简写在一个 transition 属性上:
如果使用属性的默认值,则可以省略:
使用transtion属性只是规定了要如何去过渡,要想让动画发生,还得要有元素状态的改变。如何改变元素状态呢,当然就是在css中给这个元素定义一个类(:hover等伪类也可以),这个类描述的是过渡动画结束时元素的状态。
还可以使用自定义类来实现
2D转换(transform)
浏览器支持
Internet Explorer 10, Firefox, 和 Opera支持transform 属性.
Chrome 和 Safari 要求前缀 -webkit- 版本.
注意: Internet Explorer 9 要求前缀 -ms- 版本.
例子,直径为200的圆鼠标移入后向右移动100px同时颜色渐变为红色:
3D转换
perspective:1000px; // 透视
取值为眼睛距离图片的距离 600-1000px 是人眼最舒服的距离
设置有两种方式
给父元素设置
作为transform的属性写进transform里面
transform-style:preserve-3d; // 显示出3D效果
3D 位移
3D 旋转
3D 缩放
动画
当在 @Keyframes 创建动画,把它绑定到一个选择器,否则动画不会有任何效果。
指定至少这两个CSS3的动画属性绑定向一个选择器:
关键帧的时间单位
数字:0%、25%、100%等
字符:from(0%)、to(100%)
例子:
像前面讲的transition属性一样,也可以把这些animation属性简写到一个animation中,使用默认值的也可以省略掉。但 animation-play-state 属性不能简写到animation中
参数
动画执行完成后触发的事件
当CSS 3的transition动画执行结束时,触发webkitTransitionEnd事件,使用:
animation.css使用
添加cdn引用
然后你想要哪个元素进行动画,就给那个元素添加上animated类 以及特定的动画类名,
animated
是每个要进行动画的元素都必须要添加的类。给上面的样式添加一个摇动的动画,因为摇动的动画类名为
shake
,所以代码是这样的:至于动画的效果有差异可自定义样式进行覆盖
animation.css提供动画的可用class类名
bounce
flash
pulse
rubberBand
shake
headShake
swing
tada
wobble
jello
bounceIn
bounceInDown
bounceInLeft
bounceInRight
bounceInUp
bounceOut
bounceOutDown
bounceOutLeft
bounceOutRight
bounceOutUp
fadeIn
fadeInDown
fadeInDownBig
fadeInLeft
fadeInLeftBig
fadeInRight
fadeInRightBig
fadeInUp
fadeInUpBig
fadeOut
fadeOutDown
fadeOutDownBig
fadeOutLeft
fadeOutLeftBig
fadeOutRight
fadeOutRightBig
fadeOutUp
fadeOutUpBig
flipInX
flipInY
flipOutX
flipOutY
lightSpeedIn
lightSpeedOut
rotateIn
rotateInDownLeft
rotateInDownRight
rotateInUpLeft
rotateInUpRight
rotateOut
rotateOutDownLeft
rotateOutDownRight
rotateOutUpLeft
rotateOutUpRight
hinge
jackInTheBox
rollIn
rollOut
zoomIn
zoomInDown
zoomInLeft
zoomInRight
zoomInUp
zoomOut
zoomOutDown
zoomOutLeft
zoomOutRight
zoomOutUp
slideInDown
slideInLeft
slideInRight
slideInUp
slideOutDown
slideOutLeft
slideOutRight
slideOutUp
参考
The text was updated successfully, but these errors were encountered: