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

css实现烧香效果

 效果:

代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>动态香烛效果</title><script src="https://cdn.tailwindcss.com"></script><link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet"><!-- 配置Tailwind自定义颜色和工具类 --><script>tailwind.config = {theme: {extend: {colors: {incense: {wood: '#e6c8a0',ash: '#d9d9d9',flame: '#ff6b35',glow: '#ffb74d',smoke: '#f0f0f0'}}}}}</script><style type="text/tailwindcss">@layer utilities {.incense-shadow {box-shadow: inset -2px 0 3px rgba(0,0,0,0.1), inset 2px 0 3px rgba(255,255,255,0.7);}.flame-animation {animation: flicker 1s infinite alternate;}.smoke-animation {animation: rise 4s infinite linear;}}@keyframes flicker {0% { transform: scale(1, 1); opacity: 0.9; }50% { transform: scale(1.1, 1.2); opacity: 1; }100% { transform: scale(0.9, 1); opacity: 0.85; }}@keyframes rise {0% { transform: translateY(0) scale(0.8); opacity: 0.6; }50% { transform: translateY(-20px) scale(1); opacity: 0.3; }100% { transform: translateY(-40px) scale(1.2); opacity: 0; }}</style>
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center p-4"><div class="text-center"><h1 class="text-3xl font-bold mb-8 text-gray-800">动态香烛效果</h1><!-- 香烛容器 --><div class="relative h-[400px] flex justify-center items-end mb-12"><!-- 香炉 --><div class="w-24 h-8 bg-gray-300 rounded-full mb-1 shadow-md flex items-center justify-center"><div class="w-16 h-1 bg-gray-400 rounded-full"></div></div><!-- 香烛主体 --><div id="incense-stick" class="absolute bottom-[40px] w-2 bg-incense-wood rounded-t-full incense-shadow transition-all duration-500 ease-out" style="height: 300px;"><!-- 香烛顶部燃烧部分 --><div class="w-full h-4 bg-incense-flame rounded-full flame-animation relative"><!-- 火星 --><div class="absolute -top-1 -right-1 w-2 h-2 bg-incense-glow rounded-full flame-animation"></div><!-- 烟雾 --><div class="smoke-container absolute -top-10 left-1/2 transform -translate-x-1/2 w-4 h-4"><div class="smoke smoke-animation absolute w-3 h-3 bg-incense-smoke rounded-full"></div><div class="smoke smoke-animation absolute w-4 h-4 bg-incense-smoke rounded-full" style="animation-delay: 1s; left: -2px;"></div><div class="smoke smoke-animation absolute w-2 h-2 bg-incense-smoke rounded-full" style="animation-delay: 2s; left: 2px;"></div></div></div><!-- 香烛纹理 --><div class="w-full h-full relative"><div class="absolute top-10 w-full h-1 bg-incense-ash/70"></div><div class="absolute top-40 w-full h-1 bg-incense-ash/50"></div><div class="absolute top-80 w-full h-1 bg-incense-ash/60"></div><div class="absolute top-130 w-full h-1 bg-incense-ash/40"></div><div class="absolute top-190 w-full h-1 bg-incense-ash/70"></div><div class="absolute top-250 w-full h-1 bg-incense-ash/50"></div></div></div></div><!-- 控制面板 --><div class="bg-white p-6 rounded-lg shadow-lg max-w-md mx-auto"><h2 class="text-xl font-semibold mb-4 text-gray-700">调整香的长度</h2><div class="mb-6"><label for="incense-length" class="block text-gray-600 mb-2">香长度: <span id="length-value">300</span>px</label><input type="range" id="incense-length" min="50" max="350" value="300" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer accent-amber-600"></div><div class="flex gap-3 justify-center"><button id="shorten-btn" class="px-4 py-2 bg-amber-600 text-white rounded hover:bg-amber-700 transition"><i class="fa fa-fire mr-1"></i> 燃烧变短</button><button id="reset-btn" class="px-4 py-2 bg-gray-600 text-white rounded hover:bg-gray-700 transition"><i class="fa fa-refresh mr-1"></i> 重置</button></div></div></div><script>// 获取DOM元素const incenseStick = document.getElementById('incense-stick');const lengthSlider = document.getElementById('incense-length');const lengthValue = document.getElementById('length-value');const shortenBtn = document.getElementById('shorten-btn');const resetBtn = document.getElementById('reset-btn');// 初始长度let currentLength = 300;// 更新香的长度function updateIncenseLength(length) {if (length < 50) length = 50; // 最小长度限制if (length > 350) length = 350; // 最大长度限制currentLength = length;incenseStick.style.height = `${currentLength}px`;lengthValue.textContent = currentLength;lengthSlider.value = currentLength;}// 滑块控制lengthSlider.addEventListener('input', (e) => {updateIncenseLength(parseInt(e.target.value));});// 燃烧变短按钮shortenBtn.addEventListener('click', () => {// 每次点击缩短30pxupdateIncenseLength(currentLength - 30);// 添加燃烧的视觉反馈incenseStick.classList.add('scale-95');setTimeout(() => {incenseStick.classList.remove('scale-95');}, 200);});// 重置按钮resetBtn.addEventListener('click', () => {updateIncenseLength(300);});// 自动燃烧效果 - 每5秒自动缩短一点setInterval(() => {updateIncenseLength(currentLength - 5);}, 5000);</script>
</body>
</html>


文章转载自:
http://carnivorous.alwpc.cn
http://algerian.alwpc.cn
http://alley.alwpc.cn
http://auscultatory.alwpc.cn
http://cervical.alwpc.cn
http://bushmanoid.alwpc.cn
http://brazzaville.alwpc.cn
http://aloetic.alwpc.cn
http://adoptionism.alwpc.cn
http://bravely.alwpc.cn
http://branchiae.alwpc.cn
http://aerotropism.alwpc.cn
http://aquicultural.alwpc.cn
http://baldish.alwpc.cn
http://animative.alwpc.cn
http://cabrilla.alwpc.cn
http://bovril.alwpc.cn
http://artifical.alwpc.cn
http://apospory.alwpc.cn
http://antichristian.alwpc.cn
http://catenate.alwpc.cn
http://bottlenose.alwpc.cn
http://balloonfish.alwpc.cn
http://chaliced.alwpc.cn
http://aus.alwpc.cn
http://chew.alwpc.cn
http://caballer.alwpc.cn
http://bechance.alwpc.cn
http://auricle.alwpc.cn
http://centiliter.alwpc.cn
http://www.dtcms.com/a/281753.html

相关文章:

  • 20.如何在 Python 字典中找到最小值或最大值的键?
  • 【卡尔曼滤波第六期】集合变换卡尔曼滤波 ETKF
  • 【Linux庖丁解牛】— 保存信号!
  • HTML网页结构(基础)
  • 【linux V0.11】init/main.c
  • 函数指针与指针函数练习讲解
  • 9、线程理论1
  • HostVDS 云服务器测评:平价入门、流媒体解锁全美、表现稳定
  • 暑假Python基础整理 --异常处理及程序调试
  • Redis 中的持久化机制:RDB 与 AOF
  • Java之Stream其二
  • 第二章 OB 存储引擎高级技术
  • 数学金融与金融工程:学科差异与选择指南
  • 【AI News | 20250714】每日AI进展
  • 为 Git branch 命令添加描述功能
  • 将 Vue 3 + Vite + TS 项目打包为 .exe 文件
  • 711SJBH构建制造业信息化人才培训体系的对策-开题报告
  • 21-C#的委托简单使用-1
  • Datawhale 25年7月组队学习coze-ai-assistant Task1学习笔记:动手实践第一个AI Agent—英伦生活口语陪练精灵
  • yolov5、yolov8、yolov11、yolov12如何训练及轻量化部署-netron-onnx
  • echarts折线图的 线条的样式怎么控制
  • Python os模块完全指南:从入门到实战
  • python编程实现GUI界面的排序与查找算法动态模拟演示程序
  • Sa-Token使用要点
  • mongoDB安装初始化及简单介绍
  • 2025/7/15——java学习总结
  • Pandas 和 NumPy 使用文档整理
  • 大宗现货电子盘交易系统核心功能代码解析
  • QT6 源,六章事件系统(8)QEvent 的孙子类:QEnterEvent 光标进入
  • 无穿戴动捕如何凭借摄像头视觉识别算法,赋能高校专业教学革新?