*新闻详情页*/>
本文章内容详细介绍了CSS3之transition完成下划线的示例编码,共享给大伙儿,实际以下:
在这里先看看大家的demo
了解transition
这是CSS3中新增的1个款式,能够完成动漫的过多。一般应用在加上某种实际效果能够从1种款式变化到另外一个的情况下。
transition特性
transition: width 1s linear 2s; /*简写案例*/
/*等同于以下*/ transition-property: width; transition-duration: 1s; transition-timing-function: linear; transition-delay: 2s;
tranform特性
完成大家必须的实际效果
自然,在这就立即放出编码,编码中有注解便捷了解
/*css编码*/ h2{ position: relative; padding: 15px; text-align: center; } button{ width: 100px; height: 40px; border-radius: 15px; border: none; background: #188FF7; color: #fff; outline: none; cursor: pointer; font-weight: bold; } button:hover{ background: #188EA7; } .container{ width: 600px; display: flex; flex-direction: column; align-items: center; margin: 0 auto; } .line{ position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; transition: transform .5s; background: #188EA7; color: #188EA7; transform: scaleX(0); z-index: 1111; } @keyframes changeColor1{ from{ color: #000; } to{ color: #188EA7; } } @keyframes changeColor2{ from{ color: #188EA7; } to{ color: #000; } } <!--html编码--> <div class="container"> <h2 id="title"> 百度搜索前端开发学校 <i class="line" id="line"></i> </h2> <button id="change">Change</button> </div> //js一部分编码 (function () { let btn = document.getElementById('change'); let h2 = document.getElementById('title'); let line = document.getElementById('line'); let count = 0; btn.onclick = function () { if(count%2===0){ line.style.transform = "scaleX(1)"; h2.style.animation = "changeColor1 1s"; h2.style.color = "#188EA7"; count++; }else{ line.style.transform = "scaleX(0)"; h2.style.animation = "changeColor2 1s"; h2.style.color = "#000"; count++; } } })();
总结
到这里大家就早已将此实际效果彻底展现,另外大家也学习培训了CSS3中的transition特性和tranform特性。自然进行此动漫还必须有1些html和css基本。
以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助,也期待大伙儿多多适用脚本制作之家。
Copyright © 2002-2020 上线了小程序官网_年会抽奖小程序免费_做小程序_小程序网站_跑腿小程序 版权所有 (网站地图) 粤ICP备10235580号