简介
在本教程中,我们将创建一个超优质的 3D 角斗士主题产品展示,其中包括动画产品卡、动态悬停效果、点击交互以及使每件物品栩栩如生的发光粒子效果。该展示专为沉浸式用户体验而设计,结合了 3D 变换、发光动画和脉动亮点,为每件产品带来独特的互动感觉。这个设计的灵感来自于《角斗士之战》,这是一款互动游戏,玩家可以在其中体验古代战斗和策略的快感。
跟随创建您自己的交互式产品展示,并学习如何使用 HTML、CSS 和 JavaScript 来实现令人惊叹的视觉效果和动态动画。
第 1 步:设置 HTML 结构
每张产品卡都代表一个角斗士主题的物品,例如盾牌或剑,并带有徽章、图标和统计数据等互动元素。
<meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>3D Gladiator Product Showcase</title> <link rel="stylesheet" href="styles.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> <div> <p>Key HTML Elements<br> Badge: Labels each item with statuses like "New" or "Popular."<br> Product Image: Displays the item with a glowing effect and 3D depth.<br> Stats: Uses progress bars to display item attributes like defense or attack.<br> Icons: Interactive icons at the bottom of each card provide quick access to favorite actions.<br> Step 2: Designing with CSS<br> Basic Styles and Background<br> The background uses a radial gradient to create a dramatic look, while each product card is styled with gradients, shadows, and smooth transitions.<br> </p> <pre class="brush:php;toolbar:false">body { display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0; background: radial-gradient(circle at center, #1b1b2f, #090909); font-family: Arial, sans-serif; overflow: hidden; color: #fff; } .product-showcase { display: flex; gap: 40px; perspective: 1200px; }
产品卡片样式
每张卡片均采用 3D 外观设计,并包含用于交互的悬停效果。 :hover 效果提供微妙的旋转和发光,增强高级感。
.product-card { position: relative; width: 270px; height: 420px; padding: 25px; background: linear-gradient(145deg, #2a2a2a, #3c3c3c); border-radius: 20px; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7), 0 0 20px rgba(255, 215, 0, 0.5); display: flex; flex-direction: column; align-items: center; justify-content: center; transform-style: preserve-3d; transition: transform 0.5s, box-shadow 0.5s, background 0.5s; cursor: pointer; overflow: hidden; } .product-card:hover { transform: scale(1.1) rotateY(10deg); box-shadow: 0 30px 60px rgba(255, 215, 0, 0.8), 0 0 30px rgba(255, 255, 0, 0.7); }
统计数据和进度条
我们使用进度条来展示防御力、耐久度等属性,为展示增添了独特的视觉元素。
.stats { width: 100%; margin-top: 15px; } .stat-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; color: #ffd700; font-size: 14px; font-weight: bold; } .progress { width: 60%; height: 8px; background: rgba(255, 255, 255, 0.2); border-radius: 5px; } .progress-bar { height: 100%; background: linear-gradient(90deg, #ffcc00, #f9844a); }
添加粒子效果
添加移动和改变颜色的粒子可以增强身临其境的感觉。这些粒子可以脉动产生发光效果。
.particle { position: absolute; width: 4px; height: 4px; border-radius: 50%; background: rgba(255, 215, 0, 0.9); box-shadow: 0 0 10px rgba(255, 215, 0, 0.5), 0 0 20px rgba(255, 255, 0, 0.3); animation: particleAnimation 3s ease-in-out infinite, particleMove 4s linear infinite; }
第 3 步:添加 JavaScript 交互性
JavaScript 管理悬停动画、点击事件和发光粒子效果。
添加悬停和点击动画
我们通过鼠标移动来制作卡片旋转和缩放的动画,并通过单击切换缩放。
const cards = document.querySelectorAll('.product-card'); cards.forEach((card) => { let isClicked = false; card.addEventListener('mousemove', (e) => { if (!isClicked) { const { width, height } = card.getBoundingClientRect(); const offsetX = e.clientX - card.offsetLeft - width / 2; const offsetY = e.clientY - card.offsetTop - height / 2; const rotationX = (offsetY / height) * -25; const rotationY = (offsetX / width) * 25; card.style.transform = `rotateY(${rotationY}deg) rotateX(${rotationX}deg) scale(1.05)`; } }); card.addEventListener('mouseleave', () => { if (!isClicked) { card.style.transform = 'rotateY(0deg) rotateX(0deg) scale(1)'; } }); card.addEventListener('click', () => { isClicked = !isClicked; card.style.transform = isClicked ? 'scale(1.2) rotateY(0deg) rotateX(0deg)' : 'rotateY(0deg) rotateX(0deg) scale(1)'; }); });
添加发光粒子
为了增强气氛,我们创建了在每张产品卡周围随机移动的粒子。
function addParticleEffect() { const particle = document.createElement('div'); particle.classList.add('particle'); particle.style.left = `${Math.random() * 100}%`; particle.style.top = `${Math.random() * 100}%`; particle.style.animationDuration = `${2 + Math.random() * 3}s`; document.body.appendChild(particle); setTimeout(() => particle.remove(), 5000); } setInterval(() => { cards.forEach(() => addParticleEffect()); }, 1000);
结论
利用动态动画和粒子效果构建 3D 角斗士主题产品展示,打造引人入胜的互动体验,吸引用户。通过将用于视觉样式的 CSS 和用于交互性的 JavaScript 相结合,我们创建了一个高质量的沉浸式组件,非常适合产品展示或游戏相关网站。受《角斗士之战》的启发,该展示凸显了现代网页设计与历史主题相结合的力量。
?发现更多:
探索角斗士之战:在 https://gladiatorsbattle.com 潜入古代武士和战略游戏的世界。
GitHub:查看更多项目:https://github.com/HanGPIErr。
LinkedIn:连接以获取项目更新:https://www.linkedin.com/in/pierre-romain-lopez/。
Twitter:关注 https://x.com/GladiatorsBT 了解设计和开发见解。
请继续关注有关创建引人入胜的交互式组件的更多教程!
以上是角斗士产品角斗士主题产品展示,带有动态粒子和交互式动画的详细内容。更多信息请关注PHP中文网其他相关文章!

具有CSS的自定义光标很棒,但是我们可以将JavaScript提升到一个新的水平。使用JavaScript,我们可以在光标状态之间过渡,将动态文本放置在光标中,应用复杂的动画并应用过滤器。

互动CSS动画和元素相互启动的元素在2025年似乎更合理。虽然不需要在CSS中实施乒乓球,但CSS的灵活性和力量的增加,可以怀疑Lee&Aver Lee&Aver Lee有一天将是一场

有关利用CSS背景滤波器属性来样式用户界面的提示和技巧。您将学习如何在多个元素之间进行背景过滤器,并将它们与其他CSS图形效果集成在一起以创建精心设计的设计。

好吧,事实证明,SVG的内置动画功能从未按计划进行弃用。当然,CSS和JavaScript具有承载负载的能力,但是很高兴知道Smil并没有像以前那样死在水中

是的,让#039;跳上文字包装:Safari Technology Preview In Pretty Landing!但是请注意,它与在铬浏览器中的工作方式不同。

此CSS-tricks更新了,重点介绍了年鉴,最近的播客出现,新的CSS计数器指南以及增加了几位新作者,这些新作者贡献了有价值的内容。

在大多数情况下,人们展示了@Apply的@Apply功能,其中包括Tailwind的单个property实用程序之一(会改变单个CSS声明)。当以这种方式展示时,@Apply听起来似乎很有希望。如此明显


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

Dreamweaver Mac版
视觉化网页开发工具

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中