【CSS3和JS】
对于CSS 了解 的 同学 都 知道 ,CSS的实现是最底层的,在实现方式和性能上都不是,JS这种提供接口的脚本可比的;从CSS3的动画和JS动画对比角度来看两者,会更清晰;而且随着 前端框架 的使用,页面动画会越来越多的应用CSS3
【CSS3的其他用法】
除了动画的代替,还有就是对于各种交互的实现上,也体现了CSS的强大,更多的是使用CSS3提供的选择器;
先来看个例子:可以更好的体现我这次对于CSS的深刻 感悟
<style> body{background: # f4f4f4 ;m arg in:0;} /*list*/ .list__con{} .list__con .box{background:#fff;pos IT ion:relative;border-bottom:solid 1px #858585;overflow:hidden;} .list__con .box:hover{background:#f4f4f4;- webkit -t ransition:all .6s;transition:all .6s;} .list__con .box:hover .delete{-webkit-transition:all .6s;transition:all .6s;opacity:1;} .list__con .input{-webkit-ap PE arance:none;appearance:none;position:absolute;top:10px;left:12px;padding:0;border:none;mar gin :0;width:24px;h ei ght:24px;border:solid 2px red ;border-radius:50%;box -s izing: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;dis play :block;-webkit-transition:all .4s;transition:all .4s;} .list__con .input:checked+label{color:#d9d9d9;text-decoration:line-t hr ough;} .list__con .delete{width:44px;height:44px;float:right;position:relative;cursor:pointer;opacity:0;} .list__con .delete:hover :: after{-webkit-transform:rotate(225 deg );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和js结合的方式实现;期间也尝试着全部使用css实现交互效果, 不过 却在 探索 的时候故步自封导致到现在才真正的实现当初的想法;
使用CSS完全实现的好处, 提高 了可复用性和可维护性,对于实现相应组件提供了更好的实现方式,同时也提高了性能;
&nbs p;
.list__con .input:checked+label
如上面这种用法,我们可以使用CSS3增加的各种强大的选择器,实现更多更好的交互效果;从此离开使用JS 改变 DOM的悲剧,更多的倾向于CSS
总结
以上是 为你收集整理的 使用CSS3来代替JS实现交互 全部内容,希望文章能够帮你解决 使用CSS3来代替JS实现交互 所遇到的问题。
如果觉得 网站内容还不错, 推荐好友。