You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用JavaScript实现Div的指定示例显示效果或其他炫酷样式?

炫酷Div展示效果示例与源码

当然没问题!我整理了几个实用又吸睛的Div展示效果,附上完整源码,你可以直接运行或者根据需求调整细节:

1. 动态渐变背景Div

这个效果会让Div的背景色平滑渐变循环,视觉感拉满:

<div class="gradient-div">动态渐变背景</div>

<style>
.gradient-div {
  width: 300px;
  height: 200px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  font-weight: bold;
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4);
  background-size: 400% 400%;
  animation: gradientShift 8s ease infinite;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
</style>

2. 悬停3D翻转Div

鼠标悬停时Div会做3D翻转,露出背面内容,适合卡片类展示:

<div class="flip-card">
  <div class="flip-card-inner">
    <div class="flip-card-front">
      <p>正面内容</p>
    </div>
    <div class="flip-card-back">
      <p>背面内容</p>
    </div>
  </div>
</div>

<style>
.flip-card {
  width: 300px;
  height: 200px;
  perspective: 1000px;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.flip-card:hover .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front, .flip-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.flip-card-front {
  background-color: #2c3e50;
  color: white;
}

.flip-card-back {
  background-color: #3498db;
  color: white;
  transform: rotateY(180deg);
}
</style>

3. 霓虹边框动画Div

带有闪烁霓虹边框的Div,适合突出展示重点内容:

<div class="neon-div">霓虹边框效果</div>

<style>
.neon-div {
  width: 300px;
  height: 200px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.2rem;
  font-weight: bold;
  background-color: #1a1a1a;
  position: relative;
}

.neon-div::before {
  content: "";
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: linear-gradient(45deg, #ff00ff, #00ffff, #ff00ff);
  border-radius: inherit;
  z-index: -1;
  animation: neonGlow 2s linear infinite;
}

@keyframes neonGlow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
</style>

技术提示

  • 这些效果主要依赖CSS的@keyframes动画、transform变换和渐变背景特性,无需额外JS(除了复杂交互可能需要)
  • 你可以通过修改background属性值、动画时长、边框圆角等参数,快速定制成符合自己需求的样式
  • 如果需要更复杂的交互(比如点击触发动画),可以结合JavaScript监听事件来控制CSS类的切换

内容的提问来源于stack exchange,提问作者Курносов Павел

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 11:52:38