HTML 过渡

过渡 transition
transition-property:要发生过渡的属性
默认值all
**transition-duration:持续时间 必须写
s ms1s=100ems默认值0s
transition-delay:延迟时间
s ms1s=1000ms

过渡是主动触发的,一般过渡只有在鼠标移入之后才有效所以
过渡属性要写在元素的默认状态中。

 <style>
    div{
      width: 500px;
      height: 500px;
      background-color: antiquewhite;
      /* 写过渡属性 要写在元素的默认位置 过渡一般是只在鼠标移动时才写的效果 */
      transition-property: height,background-color;
      /* 延迟时间 */
      transition-delay: 4ms;
      /* 持续时间 必须写*/
      transition-duration: 5s;
    }
    div:hover{
      height: 700px;background-color: aqua;
    }
  </style>
</head>
<body>
  <div>过渡属性</div>
</body>

过渡简写:

过渡简写
transition:要发生过渡的属性持续时间延迟时间运动状态;
-顺序不强调
-持续时间和延迟时间有先后顺序持续时间在前-持续时间必须写
-最简单的过渡
transition:持续时间
-

过渡的运动状态
transition-timing-function
ease 默认值先快后慢
linear 匀速

 <style>
    .father{
      width: 1000px;
      height: 500px;
      border: 5px black solid;
    }
    .father div{
      width: 200px;
      height: 200px;
      background-color: aquamarine;
      transition-duration: 20s;
    }
    .ease{
      transition-timing-function: ease;
    }
    .linear{
      transition-timing-function: linear;
    }
    .father:hover div{
      width: 888px;
    }
  </style>
</head>
<body>
  <div class="father">
    <div class="ease">逐渐慢</div>
    <br>
    <div class="linear">匀速</div>
  </div>
</body>

过渡中间值:只有有中间值的属性才可以发生过渡

<style>
    /* 鼠标移入父元素,子元素满满消失 */
    .father{
      width: 500px;
      height: 500px;
      background-color: aqua;

    }
    .son{
      width: 200px;
      height: 200px;
      background-color: chartreuse;
      /* 是子元素慢慢消失,应该在子元素身上写过渡 */
      transition-duration: 2s;
      margin: auto;
    }
    .father:hover .son{
      /* display:none  和   visibility:hidden都没有中间值 */
      opacity: 0;
    }
  </style>
</head>
<body>
  <div class="father">
    <div class="son">只有有中间值的属性才可以发生过渡</div>
  </div>
</body>
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值