js+css实现aqi颗粒物环形指数数值变动动画效果代码

代码语言:html

所属分类:动画

代码描述:js+css实现aqi颗粒物环形指数数值变动动画效果代码

代码标签: js css aqi 颗粒物 环形 指数 数值 变动 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  


  
  
  
<style>
:root {
  --primary-bg: #1e203a;
  --meter-bg-colors:conic-gradient(
    from 0deg,
    rgba(0, 222, 114, 1),
    rgba(255, 226, 28, 1),
    rgba(255, 141, 6, 1),
    rgba(251, 42, 63, 1),
    rgba(178, 1, 238, 1),
    rgba(109, 9, 25, 1)
  );
  --primary-color: whitesmoke;
}
/*Custom Font Import*/
@font-face {
  font-family: "clockDigital";
  src: url("//repo.bfw.wiki/bfwrepo/font/digital-7.woff2") format("woff2"),
    url("//repo.bfw.wiki/bfwrepo/font/digital-7.woff") format("woff");
}
/*CSS RESET*/
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "clockDigital";
}
/*Background properties*/
#bg {
  height: 100vh;
  background-color: var(--primary-bg);
  display: grid;
  place-items: center;
}
/*U.S.AQI meter using (EPA)category colors*/
#meter {
  position: relative;
  height: 200px;
  aspect-ratio: 1/1;
  border-radius: 100%;
  background:var(--meter-bg-colors);
  display: grid;
  place-items: center;
}
/*Inner body of meter*/
#meter:before {
  position: absolute;
  content: " ";
  padding: 90px;
  padding: 90px;
  border-radius: 100%;
  background: var(--primary-bg);
}
/*
the container for the indicator/dot to position it properly
and add a slight transition for the calculation formula in JS  
*/
#indicator {
  position: absolute;
  height: 205px;
  aspect-ratio: 1/1;
  transition:.2s;
  display: flex;
  justify-content: center;
  rotate: 5deg;
  /*animation:spin 5s linear alternate infinite;*/
}
/*The dot on the meter to indicate meters AQI level*/
#indicator:before {
  position: absolute;
  content: " ";
  padding: 5px;
  background: var(--primary-color);
  top: 0;
  border-radius: 100%;
  border: 3px solid var(--primary-bg);
}
/*AQI number*/
#current-aqi {
  position: absolute;
  letter-spacing: 1px;
  font-size: 70px;
  color: var(--primary-color);
  text-align: center;
  line-height: 20px;
}
/*SVG and AQI text*/
p {
  font-size: 20px;
  color: #999;
  position: absolute;
  top: 130px;
  display: flex;
  align-items: center;
  gap: 5px;
}
/*Particle matter SVG */
#PM {
  fill: #999;
}
/* for testing roation on the #indicator*/
@keyframes spin {
  from {
    rotate:5deg;
  }
  to {
    rotate:355deg;
  }
}
/*If user system = lightmode*/
@media (prefers-color-scheme: light) {
  /*use these settings instead*/
  :root {
    --primary-bg: #dbdbdb;
    --primary-color: rgb(61, 61, 61);
  }
    #meter::before {
    border: 1px solid black;
  }
  #indicator {
    border-radius: 100%;
    height: 200px;
    border: 1px solid black;
    aspect-ratio: 1/1;
  }
    #indicator::before {
    top: -3px;
    padding: 4px;
    border: 3px solid var(--primary-bg);
  }
}
</style>

  
  
</head>

<body >
  <div id="bg">
  <div id="meter">
    <h1 id="current-aqi">---</h1>
    <p>
      <!--PM (Particle Matter) SVG-->
      <svg height="15px" viewBox="0 0 315 359" fill="none" xmlns="http://www.w3.org/2000/svg">
        <g id="PM">
          <circle id="El.........完整代码请登录后点击上方下载按钮下载查看

网友评论0