css摇曳的_HTML5+CSS3实现树被风吹动摇晃

1

新建html文档。

2

书写hmtl代码。

3

书写css代码。

.trunk, .trunk div { background: #136086; width: 100px; height: 10px; position: absolute; left: 50%; top: 70%; margin-left: -10px; -webkit-animation-name: rot; animation-name: rot; -webkit-animation-duration: 2.02s; animation-duration: 2.02s; -webkit-animation-iteration-count: infinite; animation-iteration-count: infinite; -webkit-animation-direction: alternate; animation-direction: alternate; -webkit-transform-origin: 5px 5px; -ms-transform-origin: 5px 5px; transform-origin: 5px 5px; -webkit-animation-timing-function: ease-in-out; animation-timing-function: ease-in-out; }

.trunk.trunk, .trunk div.trunk { bottom: 0; left: 50%; -webkit-animation-name: rot-root; animation-name: rot-root; -webkit-animation-duration: 2.5s; animation-duration: 2.5s; }

.trunk > div, .trunk div > div { /*opacity:0.9;*/

top: 0; left: 100px; -webkit-animation-duration: calc(inherit / 2); animation-duration: calc(inherit / 2);/* don't works  */

}

.trunk > div:nth-child(2), .trunk div > div:nth-child(2) { /*animation-duration:15s;*/

-webkit-animation-name: rot-inv; animation-name: rot-inv; -webkit-animation-duration: 1.7s; animation-duration: 1.7s; }

4

书写css百分比代码。

@-webkit-keyframes rot {  from {

-webkit-transform: rotate(15deg) scale(0.72);

transform: rotate(15deg) scale(0.72);

}

to { -webkit-transform: rotate(45deg) scale(0.72); transform: rotate(45deg) scale(0.72); }

}

@keyframes rot {  from {

-webkit-transform: rotate(15deg) scale(0.72);

transform: rotate(15deg) scale(0.72);

}

to { -webkit-transform: rotate(45deg) scale(0.72); transform: rotate(45deg) scale(0.72); }

}

@-webkit-keyframes rot-inv {  from {

-webkit-transform: rotate(-45deg) scale(0.72);

transform: rotate(-45deg) scale(0.72);

}

to { -webkit-transform: rotate(-15deg) scale(0.72); transform: rotate(-15deg) scale(0.72); }

}

@keyframes rot-inv {  from {

-webkit-transform: rotate(-45deg) scale(0.72);

transform: rotate(-45deg) scale(0.72);

}

to { -webkit-transform: rotate(-15deg) scale(0.72); transform: rotate(-15deg) scale(0.72); }

}

@-webkit-keyframes rot-root {  from {

-webkit-transform: rotate(-95deg);

transform: rotate(-95deg);

}

to { -webkit-transform: rotate(-85deg); transform: rotate(-85deg); }

}

@keyframes rot-root {  from {

-webkit-transform: rotate(-95deg);

transform: rotate(-95deg);

}

to { -webkit-transform: rotate(-85deg); transform: rotate(-85deg); }

}

5

代码整体结构。

6

查看效果。

END

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值