首頁 > web前端 > css教學 > 主體

角鬥士產品角鬥士主題產品展示,帶有動態粒子和互動動畫

DDD
發布: 2024-11-14 15:39:02
原創
362 人瀏覽過

Gladiator Product Gladiator-Themed Product Showcase with Dynamic Particles & Interactive Animations

Introduction

In this tutorial, we’ll create an ultra-premium, 3D gladiator-themed product showcase featuring animated product cards, dynamic hover effects, click interactions, and a glowing particle effect that brings each item to life. Designed for immersive user experiences, this showcase combines 3D transformations, glowing animations, and pulsating highlights to give each product a unique and interactive feel. This design is inspired by Gladiators Battle, an interactive game where players experience the thrill of ancient battles and strategy.

Follow along to create your own interactive product showcase and learn how to use HTML, CSS, and JavaScript for stunning visuals and dynamic animations.

Step 1: Setting Up the HTML Structure
Each product card represents a gladiator-themed item, like a shield or sword, with interactive elements such as badges, icons, and stats.

<!DOCTYPE html>
<html lang="en">
<head>
  <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">
</head>
<body>
  <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;
}
登入後複製

Product Card Styles
Each card is designed with a 3D look and includes hover effects for interactivity. The :hover effect provides a subtle rotation and glow, enhancing the premium feel.

.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 and Progress Bars
We use progress bars to display attributes such as defense and durability, which add a unique visual element to the showcase.

.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);
}
登入後複製

Adding Particle Effects
Adding particles that move and change color enhances the immersive feel. These particles can pulsate to give a glowing effect.

.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;
}
登入後複製

Step 3: Adding JavaScript Interactivity
The JavaScript manages hover animations, click events, and the glowing particle effect.

Adding Hover and Click Animations
We animate the card rotation and scaling on mouse movement and toggle zoom with a click.

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)';
  });
});
登入後複製

Adding Glowing Particles
To enhance the atmosphere, we create particles that move randomly around each product card.

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);
登入後複製

Conclusion
Building a 3D gladiator-themed product showcase with dynamic animations and particle effects creates an engaging, interactive experience that can captivate users. By combining CSS for visual styling and JavaScript for interactivity, we’ve created a high-quality, immersive component ideal for product displays or gaming-related sites. Inspired by Gladiators Battle, this showcase highlights the power of combining modern web design with historical themes.

? Discover More:

探索角鬥士之戰:在 https://gladiatorsbattle.com 潛入古代武士和戰略遊戲的世界。
GitHub:查看更多項目:https://github.com/HanGPIErr。
LinkedIn:連結以取得專案更新:https://www.linkedin.com/in/pierre-romain-lopez/。
Twitter:追蹤 https://x.com/GladiatorsBT 以了解設計和開發見解。
請繼續關注有關創建引人入勝的互動式元件的更多教學!

以上是角鬥士產品角鬥士主題產品展示,帶有動態粒子和互動動畫的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板