• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

黄文超

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

css3中的过渡

css3中的过渡

1、transition的几个样式值

transition-property:设置要过渡的属性值例如(height,width)
transition-duration:设置过渡时间(必须加上时间单位)
transition-timing-function:设置过渡样式
							ease -- 先加速后减速
							linear -- 匀速变化
							ease-in -- 加速变化
							ease-out -- 减速变化
							ease-in-out -- 先加速后减速
							cubic-bezier() -- 按照该函数曲线变化
transition-delay:设置过渡的延迟时间

2、过渡动画的样式覆盖

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>过渡的样式覆盖</title>
    <style>
        .outer {
            width: 400px;
            height: 400px;
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;
            border: 1px solid;
        }
        .inner {
            width: 100px;
            height: 100px;
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;
            background-color: pink;
            text-align: center;
            font: 20px/100px "微软雅黑";
            transition-property: width;
            transition-duration: 5s;
            transition-timing-function: ease;
        }
        .outer:hover .inner {
            transition-property: height;
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
<div class="outer">
    <div class="inner">文字内容</div>
</div>
</body>
</html>
就像上述代码一样,如果在其他地方hover或者是怎么样,那么它的样式会根据最新的发生改变

3、过渡动画的绑定时机

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>过渡的天坑</title>
    <style>
        .outer {
            width: 400px;
            height: 400px;
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;
            border: 1px solid;
        }
        .inner {
            width: 100px;
            height: 100px;
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;
            background-color: pink;
            text-align: center;
            font: 20px/100px "微软雅黑";
            transition-property: width,height;
            transition-duration: 5s;
            transition-timing-function: ease;
            transition-delay: 2s;
        }
    </style>
</head>
<body>
<div class="outer">
    <div class="inner">文字内容</div>
</div>
</body>
<script>
    // transition只能是首次页面渲染完成后才能被触发
    window.onload = function () {
        var inner = document.getElementsByClassName("inner")[0]
        var outer = document.getElementsByClassName("outer")[0]
        inner.style.width = "200px"
    }
</script>
</html>
transition只能是首次页面渲染完成后才能被触发

posted on 2021-10-31 19:36  黄文超  阅读(102)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3