javascript创建的温度计滑块小部件

所属分类: 网页特效-实用工具    2024-01-14 09:34:45

javascript创建的温度计滑块小部件 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript创建的温度计滑块小部件(共3个文件)

    • index.html

使用方法

const units = {
  Celcius: "°C",
  Fahrenheit: "°F" };

const config = {
  minTemp: -20,
  maxTemp: 50,
  unit: "Celcius" };


// Change min and max temperature values

const tempValueInputs = document.querySelectorAll("input[type='text']");

tempValueInputs.forEach(input => {
  input.addEventListener("change", event => {
    const newValue = event.target.value;

    if (isNaN(newValue)) {
      return input.value = config[input.id];
    } else {
      config[input.id] = input.value;
      range[input.id.slice(0, 3)] = config[input.id]; // Update range
      return setTemperature(); // Update temperature
    }
  });
});

// Switch unit of temperature

const unitP = document.getElementById("unit");

unitP.addEventListener("click", () => {
  config.unit = config.unit === "Celcius" ? "Fahrenheit" : "摄氏度";
  unitP.innerHTML = config.unit + ' ' + units[config.unit];
  return setTemperature();
});

// Change temperature

const range = document.querySelector("input[type='range']");
const temperature = document.getElementById("temperature");

function setTemperature() {
  temperature.style.height = (range.value - config.minTemp) / (config.maxTemp - config.minTemp) * 100 + "%";
  temperature.dataset.value = range.value + units[config.unit];
}

range.addEventListener("input", setTemperature);
setTimeout(setTemperature, 1000);

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

jquery页面右下角鼠标悬停滑动显示的在线客服特效代码

一款页面右侧浮动固定的在线客服代码,鼠标悬停于图标上触发动画滑动显示联系方式,可显示文本文字或图片。
  实用工具
 8681  0

jquery支持自定义的随机字符串生成器

一款支持的随机字符串生成器,可用于生成指定长度和强度的随机字符密码。字符强度设置:纯数字0~9、大写A~Z、小写A~Z。
  实用工具
 4709  0

jquery中文汉字转汉语拼音插件

一款汉字转拼音在线工具,支持任何汉字输入,点击转换即可转换成对应的拼音。
  实用工具
 7742  0

jquery基于highlight.js在线代码编辑器工具

一款轻量级代码编辑器实用工具,主要功能:代码高亮显示、可调整大小的文本区域和代码行缩进。
  实用工具
 1872  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论