首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[分享]css3扩散动画样式

发布于 2024-11-11 15:39:07
0
12

CSS3扩散动画样式能够为我们的网页带来更好的视觉效果和用户体验。本篇文章主要介绍几种常用的扩散动画样式。/ 扩散动画样式一 / .box { width: 100px; height: 100px;...

CSS3扩散动画样式能够为我们的网页带来更好的视觉效果和用户体验。本篇文章主要介绍几种常用的扩散动画样式。

/* 扩散动画样式一 */
.box {
  width: 100px;
  height: 100px;
  background-color: #03A9F4;
  position: relative;
}
.box::before {
  content: "";
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #03A9F4;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  opacity: 0;
  transition: all 0.5s ease-in-out;
}
.box:hover::before {
  transform: scale(3);
  opacity: 1;
}

/* 扩散动画样式二 */
.box {
  width: 120px;
  height: 120px;
  background-color: #F44336;
  position: relative;
}
.box::before {
  content: "";
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #F44336;
  position: absolute;
  top: -10px;
  left: -10px;
  z-index: -1;
  opacity: 0;
  transition: all 0.5s ease-in-out;
}
.box:hover::before {
  transform: scale(1.5);
  opacity: 1;
}

/* 扩散动画样式三 */
.box {
  width: 150px;
  height: 45px;
  background-color: #4CAF50;
  position: relative;
  overflow: hidden;
}
.box::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: #FFF;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  animation: pulse 1.5s ease-out infinite;
}
@keyframes pulse {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: scale(1.7);
    opacity: 0;
  }
}
.box:hover::before {
  animation: none;
}

/* 扩散动画样式四 */
.box {
  width: 100px;
  height: 100px;
  background-color: #9C27B0;
  position: relative;
  overflow: hidden;
}
.box::before {
  content: "";
  width: 130px;
  height: 130px;
  border-radius: 50%;
  position: absolute;
  top: -15px;
  left: -15px;
  transform: scale(0);
  opacity: 1;
  animation: ripple 1s linear infinite;
  background-image: radial-gradient(circle, #FFF, #FFF 35%, transparent 40%);
}
@keyframes ripple {
  0% {
    transform: scale(0);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
} 

以上是几种常用的扩散动画样式,它们的实现原理都是利用CSS的伪元素和动画属性来实现。我们可以根据需求来选用不同的样式,让网页更加丰富多彩。

评论
一个月内的热帖推荐
91云脑
Lv.1普通用户

62849

帖子

14

小组

291

积分

赞助商广告
站长交流