当前位置: 首页 > news >正文

网站推广广告 优帮云站长工具权重

网站推广广告 优帮云,站长工具权重,精准引流获客软件,网站建设 自动生成效果 实现方式 计时器:setTimeout或setInterval来计时。setInterval和 setTimeout 在某些情况下可能会出现计时不准确的情况。这通常是由于JavaScript的事件循环机制和其他代码执行所需的时间造成的。 问询:通过getCurrentLight将每个状态的持续时间设置…

效果

在这里插入图片描述

实现方式

  • 计时器:setTimeoutsetInterval来计时。setIntervalsetTimeout 在某些情况下可能会出现计时不准确的情况。这通常是由于JavaScript的事件循环机制和其他代码执行所需的时间造成的。
  • 问询:通过getCurrentLight将每个状态的持续时间设置为精确的值,并使用requestAnimationFrame来递归调用getCurrentLight函数,我们可以更准确地控制交通灯的状态。

源码

index.html

<!DOCTYPE html>
<html><head><title>交通灯</title><link type="text/css" rel="styleSheet" href="./index.css" /></head><body><div class="traffic-light"><div class="traffic-container"><div class="light green"></div><div class="light yellow"></div><div class="light red"></div></div><div class="time">90</div></div><script type="module">import {TrafficLight} from './TrafficLight.js';const time = document.querySelector('.time');const trafficDom = document.querySelector('.traffic-light');const light = new TrafficLight({red:3,yellow:2,green:5,initial:'red',});function raf(){requestAnimationFrame(()=>{raf();const current = light.getCurrentLight();time.textContent =current.remain;trafficDom.className = `traffic-light ${current.color}`;console.log(current.color,current.remain);})}raf();</script></body>
</html>

index.css

* {margin: 0;padding: 0;box-sizing: border-box;
}body{width: 100vw;height: 100vh;margin: 0;/* backgroud: #191c29 */background: #fff;
}.traffic-light{width: 200px;margin: 10px auto;-webkit-box-flex: inherit;text-align: center;
}.light{width: 20px;height: 20px;border-radius: 10px;display:inline-block;background-color: gray;margin: 10px auto;
}.red .red{background-color: red;
}.green .green{background-color: green;
}
.yellow .yellow{background-color: yellow;
}.time{font-family: 'DS-Digital';font-size: 40px;
}

TrafficLight.js

export class TrafficLight {constructor(options) {const {red = 60,green = 60,yellow = 3,initial = 'green',} = options || {};this._colors ={red:{seconds: red,next:'yellow',},green:{seconds: green,next:'yellow',},yellow:{seconds : yellow,},};this._switch(initial);}_switch(color){this._currentColor = color;this._seconds = this._colors[color].seconds;this._time = Date.now();}_next(){if(this._currentColor === 'red'){this._colors.yellow.next = 'green';}  else if(this._currentColor === 'green'){this._colors.yellow.next = 'red';} else{}this._switch(this._colors[this._currentColor].next);
}getCurrentLight(){const remain = Math.ceil(this._seconds -(Date.now() - this._time)/1000);if(remain<=0){this._next();return this.getCurrentLight();}return {color: this._currentColor,remain,};}}

字体 DS-Digital

下载字体 DS-Digital
注意:下载安装字体后需要重启浏览器才生效

http://www.hrbkazy.com/news/24977.html

相关文章:

  • 外贸电商网站开发建站软件可以不通过网络建设吗
  • 宁夏建设工程质量监督站网站广州seo顾问seocnm
  • 旅游网站对比模板下载网店怎么推广和宣传
  • 网站备案需要准备哪些资料推广平台哪个效果最好
  • 设计 网站 源码百度引擎搜索引擎
  • 网站建设哪家公司便宜怎样做网站推广啊
  • 怎样低成本做网站推广在线网站seo优化
  • 博物馆网站 微信 微博 建设方案sem工资
  • 新兴县城乡建设局网站如何在网上推广自己的公司
  • 设计院排名前十强seo课程培训课程
  • 网站建设活动策划人大常委会委员长
  • 公司网站域名实名认证怎么做百度新闻下载安装
  • WordPress主题先生杭州seo营销公司
  • 网站备案信息查询接口指数基金投资指南
  • 中山快速做网站公司佛山本地网站建设
  • 公众号开发苹果手机自定义菜单百度seo快速提升排名
  • 用什么软件开发手机appseo技术培训茂名
  • 做羞羞事网站标题优化怎样选关键词
  • 哪种类型的网站比较难做百度seo外包
  • 网站开发所需开发环境国家新闻最新消息今天
  • 做ps兼职的网站有哪些企业网站建设的一般要素
  • 旅行网站系统北京seo薪资
  • 网站开发设计流程图广告软文范例大全100字
  • 海口做网站公司哪家好最新app推广
  • axsure建设网站网络营销的特征
  • dw表格怎么做网站搜索网店代运营一年的费用是多少
  • 郑州汉狮做网站费用seo美式
  • 服装网站建设策划书seo营销培训
  • 西宁做网站制作的公司哪家好优化网站页面
  • 做炭化料的网站外链网盘下载