12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
- #box {
- width: 200px;
- height: 200px;
- background: aqua;
- margin: 100px auto;
- transition: width 5s linear 1s;
- }
- </style>
- </head>
- <body>
- <!--
- transition允许css的属性值在一定的时间区间内平滑地过渡。
- transition主要包含四个属性值:
- transition-property:all 表示要参与过渡的属性 all是默认值
- transition-duration:3s 表示动画持续的时长和速度曲线 默认值0(时长决定速度)
- transition-timing-function:linear 动画运动的方式类型
- (ease:默认值 linear:匀速运动 ease-in:表示由慢到快 ease-out:表示由快到慢 ease-in-out:慢快慢)
- transition-delay:1s 动画的延迟时间
- IOS下safari渲染transition时出现闪屏问题,解决方法:
- backface-visibility:hidden;背面可见度
- display:none;的元素并不支持css3动画
- -->
- <div id="box"></div>
- <button id="btn">放大</button>
- <button id="btn1">缩小</button>
- <script>
- var box = document.getElementById("box");
- var btn = document.getElementById("btn");
- var btn1 = document.getElementById("btn1");
- btn.onclick = function() {
- box.style.width = 500 + 'px';
- }
- btn1.onclick = function() {
- box.style.width = 200 + 'px';
- }
- </script>
- </body>
- </html>
|