CSS红绿灯,JS知识点(二)

昨天早早的就睡了,没有写。这篇是css实现红绿灯,也写在js知识点里吧,每天知识的积累,不一定是js,哈哈哈哈。

HTML部分

<div class="trafic-light">
  <div class="i red"></div>
  <div class="i orange"></div>
  <div class="i green"></div>
</div>

CSS部分

.trafic-light {padding:10px;background-color:#333;border:2px solid #000;width:30px;border-radius:10px;}
.i {margin:5px 0;height:26px;border:2px solid #000;border-radius:50%;animation-duration:10s;animation-timing:linear;-webkit-animation-iteration-count: infinite;animation-iteration-count: infinite;}
.red {background-color:#300;animation-name:redlight;}
.orange {background-color:#430;animation-name:orangelight;}
.green {background-color:#030;animation-name:greenlight;}

@keyframes redlight {
  0% {
    background-color:#f00;
  }
  39% {
    background-color:#f00;
  }
  40% {
    background-color:#300;
  }
}
@keyframes orangelight {
  0% {
    background-color:#430;
  }
  39% {
    background-color:#430;
  }
  40% {
    background-color:#fc0;
  }
  59% {
    background-color:#fc0;
  }
  60% {
    background-color:#430;
  }
}
@keyframes greenlight {
  0% {
    background-color:#030;
  }
  59% {
    background-color:#030;
  }
  60% {
    background-color:#0a0;
  }
  99% {
    background-color:#0a0;
  }
  100% {
    background-color:#030;
  }
}

这里主要是对CSS3中animation的一个应用。效果图如下:

trafigLight.gif
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 5,784评论 0 2
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 6,831评论 0 11
  • 大部分的后端会很很鄙视前端。我也不知道为什么,可能大部分人都会觉得脚本语言根本不算语言。 大多人 会叫我们切图仔,...
    小黑的眼阅读 8,773评论 0 15
  • 每当宾客向迪士尼乐园和度假区主席汤世德说起在迪士尼开心游玩,以及难忘的服务体验后。接下来总会问道:“迪士尼是如何做...
    杨婠婠阅读 4,687评论 0 1
  • 在 Swift 中,为了避免 Notification 名称直接使用字符串不安全,引入了 NSNotificati...
    SmallflyBlog阅读 5,664评论 0 1