css transtion不生效_css3 transition过度详解

CSS3中,我们为了添加某种效果可以从一种样式转变到另一个的时候,无需使用Flash动画或JavaScript。

通过过渡transition,可以让web前端开发人员不需要javascript就可以实现简单的动画交互效果。

它的工作原理就是元素从一种样式逐渐改变为另一种的效果

要实现这一点,必须规定两项内容:指定要添加效果的CSS属性

指定效果的持续时间。

div {

width: 100px;

height: 100px;

background: red;

transition: width 2s;

}

div:hover {

width: 300px;

}

hello

注意:如果未指定的时间,transition将没有任何效果,因为默认值是0。

transition支持多项改变

要添加多个样式的变换效果,添加的属性由逗号分隔:

div {

width: 100px;

height: 100px;

background: red;

transition: width 2s, height 2s

}

div:hover {

width: 300px;

height: 200px;

}

hello

transition 有四个子属性:

transition-property: 规定应用过渡的 CSS 属性的名称

transition-duration: 定义过渡效果花费的时间。默认是 0。

transition-delay: 规定过渡效果何时开始。默认是 0。

transition-timing-function: 规定过渡效果的时间曲线。默认是 "ease"。

transition-property指定需要过渡的CSS属性。

并不是所有属性都能过渡的,只有能数字量化的CSS属性才能过渡。

如 width,height,top,right,bottom,left,opacity 等等。

像 displat:block这些显示隐藏就没有过度效果

transition-property有三个属性

none 没有属性会获得过渡效果。

all 所有属性都将获得过渡效果。

property 定义应用过渡效果的 CSS 属性名称列表,列表以逗号分隔。

demo:

div {

width: 100px;

height: 100px;

background: red;

transition: all 2s

}

div:hover {

width: 300px;

height: 200px;

}

hello

transition-duration 过渡需要的时间

单位可指定s秒,也可指定ms毫秒。默认值是0,表示立刻变化

transition-timing-function 属性指定切换效果的速度。

div {

width: 100px;

height: 50px;

background: red;

margin-bottom: 5px;

transition: all 2s

}

#div1 {transition-timing-function: linear;}

#div2 {transition-timing-function: ease;}

#div3 {transition-timing-function: ease-in;}

#div4 {transition-timing-function: ease-out;}

#div5 {transition-timing-function: ease-in-out;}

div:hover {

width: 300px;

}

linear
ease
ease-in
ease-out
ease-in-out

transition-delay 属性指定何时将开始切换效果。

transition-delay值是指以秒为单位(S)或毫秒(ms)。

默认值为 0 表示不延迟,立即开始过渡动作

div {

width: 100px;

height: 100px;

background: red;

text-align: center;

margin-bottom: 5px;

transition-property:width;

transition-duration:3s;

transition-delay:1s;

}

div:hover {

width: 300px;

}

这里可以看到,过度效果会停顿 1 秒后产生效果。知乎视频​www.zhihu.comhttps://www.bilibili.com/video/BV1Xz411e7Uy/?p=104​www.bilibili.com

记得关注收藏哦!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值