【CSS3和JS】
对于CSS了解的同学都知道,CSS的实现是最底层的,在实现方式和性能上都不是JS这种提供接口的脚本可比的,从CSS3的动画和JS动画对比角度来看两者,会更清晰。而且随着前端框架的使用,页面动画会越来越多的应用CSS3。
【CSS3的其他用法】
除了动画的代替,还有就是对于各种交互的实现上,也体现了CSS的强大,更多的是使用CSS3提供的选择器;
先来看个例子:可以更好的体现于CSS
<style>
body{background:#f4f4f4;margin:0;}
/*list*/
.list__con{}
.list__con .box{background:#fff;position:relative;border-bottom:solid 1px #858585;overflow:hidden;}
.list__con .box:hover{background:#f4f4f4;-webkit-transition:all .6s;transition:all .6s;}
.list__con .box:hover .delete{-webkit-transition:all .6s;transition:all .6s;opacity:1;}
.list__con .input{-webkit-appearance:none;appearance:none;position:absolute;top:10px;left:12px;padding:0;border:none;margin:0;width:24px;height:24px;border:solid 2px red;border-radius:50%;box-sizing:border-box;outline:none;cursor:pointer;}
.list__con .input:checked::after{content:'';width:14px;height:14px;background:red;position:absolute;top:3px;left:3px;border-radius:50%;}
.list__con label{line-height:24px;padding:10px 0 10px 48px;display:block;-webkit-transition:all .4s;transition:all .4s;}
.list__con .input:checked+label{color:#d9d9d9;text-decoration:line-through;}
.list__con .delete{width:44px;height:44px;float:right;position:relative;cursor:pointer;opacity:0;}
.list__con .delete:hover::after{-webkit-transform:rotate(225deg);transform:rotate(225deg);}
.list__con .delete:hover::before{-webkit-transform:rotate(225deg);transform:rotate(225deg);}
.list__con .delete::after{content:'';position:absolute;width:2px;height:20px;background:red;top:12px;left:50%;margin-left:-1px;-webkit-transform:rotate(45deg);transform:rotate(45deg);border-radius:4px;-webkit-transition:all .6s;transition:all .6s;}
.list__con .delete::before{content:'';position:absolute;width:20px;height:2px;background:red;top:50%;left:12px;margin-top:-1px;-webkit-transform:rotate(45deg);transform:rotate(45deg);border-radius:4px;-webkit-transition:all .6s;transition:all .6s;}
</style>
<div class="list__con">
<div class="box">
<div class="delete"></div>
<input class="input" type="checkbox" />
<label>啥地方垃圾费</label>
</div>
</div>
啥地方垃圾费
【说明】
上面包括了诸多的交互,hover的交互、checked的交互。
使用CSS完全实现的好处,提高了可复用性和可维护性,对于实现相应组件提供了更好的实现方式,同时也提高了性能;
.list__con .input:checked+label
如上面这种用法,我们可以使用CSS3增加的各种强大的选择器,实现更多更好的交互效果;从此离开使用JS改变DOM的悲剧,更多的倾向于CSS。
【憧憬】相信未来的CSS将会更强大,交互方面的事情都由CSS来完成;JS更多的是回归本体。
- 还没有人评论,欢迎说说您的想法!