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

WordPress中销售倒计时html小部件

效果图

image

 

代码

<div id="flash-sale-bar-v2"><div class="fs-bar"><svg class="fs-icon" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M43.7 6.73a5 5 0 0 0-2.19-2.19 5.07 5.07 0 0 0-1.93-.5C38.99 4 38.29 4 37.5 4h-8.84c-1.5 0-2.59 0-3.63.25a9 9 0 0 0-2.6 1.08c-.91.55-1.68 1.32-2.74 2.38L6.31 21.1A53.37 53.37 0 0 0 3.53 24a8.18 8.18 0 0 0-1.65 2.77 8 8 0 0 0 0 4.95c.33 1.03.92 1.9 1.65 2.76.7.83 1.65 1.77 2.78 2.9l4.55 4.55a53.4 53.4 0 0 0 2.9 2.78 8.18 8.18 0 0 0 2.77 1.66 8 8 0 0 0 4.94 0 8.18 8.18 0 0 0 2.77-1.66 53.4 53.4 0 0 0 2.9-2.78l13.39-13.39c1.06-1.06 1.83-1.82 2.39-2.73a9 9 0 0 0 1.07-2.6c.25-1.05.25-2.13.25-3.63v-8.85c0-.78 0-1.48-.05-2.06a5.07 5.07 0 0 0-.5-1.94ZM32 20a4 4 0 1 1 0-8 4 4 0 0 1 0 8Z"/></svg><div class="fs-text"><span class="fs-label">Flash sale ends in</span><span id="fs-timer-v2" class="fs-timer">09:03:34</span></div><button type="button" class="fs-close" aria-label="Close"><svg viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M38.7 12.12a1 1 0 0 0 0-1.41l-1.4-1.42a1 1 0 0 0-1.42 0L24 21.17 12.12 9.3a1 1 0 0 0-1.41 0l-1.42 1.42a1 1 0 0 0 0 1.41L21.17 24 9.3 35.88a1 1 0 0 0 0 1.41l1.42 1.42a1 1 0 0 0 1.41 0L24 26.83 35.88 38.7a1 1 0 0 0 1.41 0l1.42-1.42a1 1 0 0 0 0-1.41L26.83 24 38.7 12.12Z"/></svg></button></div>
</div><style>#flash-sale-bar-v2,#flash-sale-bar-v2 * {box-sizing: border-box;}#flash-sale-bar-v2 {width: 100%;font-family: Arial, Helvetica, sans-serif;}#flash-sale-bar-v2 .fs-bar {width: 100%;display: flex;align-items: center;gap: 8px;padding: 8px 16px;background: #fff1f4 !important;   /* 图一浅粉背景 */border: none !important;border-radius: 0 !important;box-shadow: none !important;line-height: 1;}#flash-sale-bar-v2 .fs-icon {width: 16px;height: 16px;flex: 0 0 16px;fill: #e10543 !important;         /* 左侧图标红色 */display: block;}#flash-sale-bar-v2 .fs-text {display: flex;align-items: center;gap: 4px;min-width: 0;white-space: nowrap;flex: 1 1 auto;font-size: 14px;line-height: 20px;}#flash-sale-bar-v2 .fs-label {color: #111111 !important;        /* 文字黑色 */font-weight: 600;}#flash-sale-bar-v2 .fs-timer {color: #e10543 !important;        /* 倒计时红色 */font-weight: 700;}#flash-sale-bar-v2 .fs-close {width: 16px;height: 16px;padding: 0;margin: 0;background: transparent !important;border: none !important;box-shadow: none !important;cursor: pointer;display: inline-flex;align-items: center;justify-content: center;flex: 0 0 16px;}#flash-sale-bar-v2 .fs-close svg {width: 16px;height: 16px;fill: #e10543 !important;         /* 右侧X红色 */display: block;}@media (max-width: 767px) {#flash-sale-bar-v2 .fs-bar {padding: 8px 16px;gap: 8px;}#flash-sale-bar-v2 .fs-text {font-size: 14px;line-height: 20px;}#flash-sale-bar-v2 .fs-icon,#flash-sale-bar-v2 .fs-close,#flash-sale-bar-v2 .fs-close svg {width: 16px;height: 16px;}}
</style><script>(function () {var timerEl = document.getElementById("fs-timer-v2");var closeBtn = document.querySelector("#flash-sale-bar-v2 .fs-close");var wrap = document.getElementById("flash-sale-bar-v2");var initialTime = "09:03:34"; // 这里改成你要的初始时间
function toSeconds(str) {var arr = str.split(":");return parseInt(arr[0], 10) * 3600 + parseInt(arr[1], 10) * 60 + parseInt(arr[2], 10);}function pad(num) {return num < 10 ? "0" + num : String(num);}function toTime(total) {var h = Math.floor(total / 3600);var m = Math.floor((total % 3600) / 60);var s = total % 60;return pad(h) + ":" + pad(m) + ":" + pad(s);}var resetSeconds = toSeconds(initialTime);var currentSeconds = resetSeconds;function render() {timerEl.textContent = toTime(currentSeconds);}render();setInterval(function () {currentSeconds--;if (currentSeconds < 0) {currentSeconds = resetSeconds;}render();}, 1000);closeBtn.addEventListener("click", function () {wrap.style.display = "none";});})();
</script>

 

http://www.jsqmd.com/news/519529/

相关文章:

  • 【手把手教程】阿里云OpenClaw一键部署指南,两步解锁龙虾AI助理!
  • 【节点】[SampleTexture3D节点]原理解析与实际应用
  • React15 - Redux-Persit 中 asyncSessionStorage 在web浏览器中存在吗?
  • 电动汽车动力系统匹配计算模型及整车动力经济性计算模型
  • Godot游戏练习01-第16节-游戏中的状态机
  • 如何在 Claude Code 中无缝接入 Gemini API
  • 202603222239_《九宫格(wrap-4)》 - Coca
  • 实践一 网络攻防环境的搭建
  • 基于分层控制的车辆稳定性优化控制策略与仿真搭建
  • 避坑指南:Containerd镜像加速新旧版本配置差异详解
  • 依旧生活日记
  • 品牌在豆包做AI广告推广联系哪家公司? - 品牌2026
  • 豆包推广效果怎么样?2026企业AI获客实战指南 - 品牌2026
  • 动态规划实战:用Python手把手教你构建最优二叉查找树(附完整代码)
  • Spring IOC 源码学习 事务增强相关的对象创建
  • 2026年03月21日最热门的开源项目(Github)
  • 避坑指南:C# NumericUpDown控件5个常见错误用法及正确姿势
  • Uniapp实战:5分钟搞定谷歌地图选点定位(附完整代码与避坑指南)
  • STLink维修避坑指南:为什么你的固件刷写总失败?从写保护解除到芯片选型详解
  • 2026-03-22 全国各地响应最快的 BT Tracker 服务器(联通版)
  • python cosyVoice实现tts文本转语音、音频(未完成)
  • 别再死记硬背了!用Keil5和STM32F103C8T6搞懂GPIO八种模式,看这篇就够了
  • QCLAW 浏览器联通指南:原理、架构与配置详解
  • 大容量硬盘空间管理实战:用EternalBlaze硬链接技术优化TB级存储资源
  • LabVIEW打造轻量级无人机GCS地面站:从地平仪到电子地图的全流程解析
  • 从杜邦分析到RFM模型:手把手教你用Excel实现7大商业分析框架
  • 从YouTube到国内大厂,VPU(视频处理单元)如何重塑视频云的技术栈?
  • 重复文件处理的三种方案对比:删除、压缩还是硬链接?EternalBlaze实测报告
  • 深搜算法 6300:Grid Path Construction(2418)
  • 从吾爱论坛到开源神器:EternalBlaze作者的技术初心与硬链接工具诞生记