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

网站推广策略包括哪些内容邯郸哪里可以学建网站

网站推广策略包括哪些内容,邯郸哪里可以学建网站,wordpress整站源码,老专家个人网站效果 实现方式 计时器: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.yayakq.cn/news/92092/

相关文章:

  • 网站建设基础 ppt白云区专业网站建设
  • 山东住房和城乡建设厅网站上海外贸网站建
  • 如何做自己的网站商城开发网站教程
  • 网站防采集建网站不想用怎样撤销
  • 建设电影网站论文wordpress上传七牛
  • 植物网站模板网站开发都需要什么
  • 做网站的公司怎么拓展业务做网站哪种字体好看
  • 怎么看别人网站怎么做的优化蓬莱建网站
  • 太原网站开发工程师wordpress 配置数据库
  • 质感网站系统下载 锐狐青岛建设银行网站首页
  • 企业网站cms系统在线网站代码生成器
  • 计算机学习网站seo优化标题 关键词
  • 广州智能建站软件wordpress html5插件
  • 销售怎么找客户小红书seo排名帝搜软件
  • 网站建设介绍大全嘉定网络公司
  • 云南文山网站建设费用网站开发的现状分析
  • 主机网站建设制作农村自建房设计图纸大全
  • 电器企业网站建站怎样在网站上做友情链接
  • 工作网站建设动易做网站如何
  • html网页建设网站代码wordpress数据库域名表
  • 中文域名查询网站wordpress被自动发布文章
  • 免费做网站方案域名备案和网站备案
  • 个人做信息分类网站需备案吗wordpress结构
  • 秦皇岛建设局网站6杭州旺道企业服务有限公司
  • 聊城网站建设公司电话网站flash背景
  • 辛集seo网站优化wordpress+伪静态+403
  • 安徽龙山建设网站西部数码做的网站打不开
  • 做服务的网站浏览器免费下载
  • 冠县做网站哪里好做网站还需要兼容ie8吗
  • 企业门户网站建设优势网站如何做微信推广