html - 悬停时的关键帧动画

标签 html css keyframe

我一直在关注 CSS 关键帧动画的示例,代码如下:-

.pulse-animation {
  margin: 50px;
  display: block;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #ff8717;
  cursor: pointer;
  animation: pulse 2s infinite;
  float: left;
}

.pulse-animation:hover {
  animation: none;
}

@keyframes pulse {
  0% {
    -moz-box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
    box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
  }
  70% {
    -moz-box-shadow: 0 0 0 30px rgba(204, 169, 44, 0);
    box-shadow: 0 0 0 30px rgba(204, 169, 44, 0);
  }
  100% {
    -moz-box-shadow: 0 0 0 0 rgba(204, 169, 44, 0);
    box-shadow: 0 0 0 0 rgba(204, 169, 44, 0);
  }
}
<span class="pulse-animation"></span>
<img class="pulse-animation" src="https://randomuser.me/api/portraits/women/1.jpg" />
<img class="pulse-animation" src="https://randomuser.me/api/portraits/women/2.jpg" />
<img class="pulse-animation" src="https://randomuser.me/api/portraits/women/3.jpg" />
<img class="pulse-animation" src="https://randomuser.me/api/portraits/women/4.jpg" />

我尝试让动画仅适用于悬停但它没有用,我也尝试更改悬停动画但它仍然不起作用所以任何人都可以提供帮助。

最佳答案

:hover 是您将鼠标悬停在该元素上方时的状态。 当您不悬停时,您不希望有动画,因此您将 animation: none; 设置为默认状态 .pulse-animation。如果您将鼠标悬停在类 .pulse-animation 上,那么您将设置 animation: pulse 2s infinite;

看下面的例子

.pulse-animation {
  margin: 50px;
  display: block;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #ff8717;
  cursor: pointer;
  animation: none;
  float: left;
}

.pulse-animation:hover {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    -moz-box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
    box-shadow: 0 0 0 0 rgba(204, 169, 44, 0.4);
  }
  70% {
    -moz-box-shadow: 0 0 0 30px rgba(204, 169, 44, 0);
    box-shadow: 0 0 0 30px rgba(204, 169, 44, 0);
  }
  100% {
    -moz-box-shadow: 0 0 0 0 rgba(204, 169, 44, 0);
    box-shadow: 0 0 0 0 rgba(204, 169, 44, 0);
  }
}
<span class="pulse-animation"></span>
<img class="pulse-animation" src="https://randomuser.me/api/portraits/women/1.jpg" />
<img class="pulse-animation" src="https://randomuser.me/api/portraits/women/2.jpg" />
<img class="pulse-animation" src="https://randomuser.me/api/portraits/women/3.jpg" />
<img class="pulse-animation" src="https://randomuser.me/api/portraits/women/4.jpg" />

关于html - 悬停时的关键帧动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50331594/

相关文章:

python - 如何使用 web.py 显示图像

UIWebView 中的 iPhone 键盘不会消失

html - 页脚重叠内容 - HTML 和 CSS

css - 一堆 Bootstrap 类或在主 css 中创建自定义 css 类?

javascript - 将元素的属性强制为某个值,即使它正在动画

animation - 分享很棒的 CSS3 技巧的地方

css - 变换在同一旋转中旋转度数

javascript - 我在每隔几秒更改一次图像时遇到麻烦,同时还要以 100% 的高度和宽度响应地缩放图像

javascript - 为目标 div 设置默认内容

javascript - 我知道如何使用 javascript (getElementById) 更改文本,但如何使该文本包含例如。链接?