【问题标题】:How to get a keyframe to make a bell appear as if it is ringing如何获取关键帧以使铃声看起来好像在响铃
【发布时间】:2019-06-26 23:54:32
【问题描述】:

我正在尝试创建一个关键帧,以使铃铛的图片看起来像是在响铃。截至目前,关键帧没有运行或至少看起来没有运行。

有人看到我做错了吗?

#subscribeButton {
	width: 50%;
	height: 150px;
	background: #1b8c00;
	background: #5fae4c;
	border: 2px solid #FFF;
	position: fixed;
	left: 0;
	bottom: 0;
	cursor: pointer;
}
#subscribeButton img {
	width: 70px;
	height: auto;
	display: block;
	margin: 10px auto;
	text-align: center;
	-webkit-animation-name: shake;
	animation-name: shake;
	-webkit-animation-duration: 0.4s;
	animation-duration: 0.4s;
    animation-timing-function: ease-in-out;
	animation-iteration-count: 2;
	animation-delay: 2s;
   /* transform-origin(50% 6px);*/
}
#subscribeButtonText {
	color: #FFF;
	font-family: Verdana, sans-serif;
	font-size: .8rem;
	padding: 5px;
	text-align: center;
	text-transform: uppercase;
}

@-webkit-keyframes shake {
  0%, 100% { transform(rotate(0)); }
  20%, 60%    { transform(rotate(6deg)); }
  40%, 80% { transform(rotate(-6deg)); }
}

@keyframes shake {
  0%, 100% { transform(rotate(0)); }
  20%, 60%    { transform(rotate(6deg)); }
  40%, 80% { transform(rotate(-6deg)); }
}
<div id="subscribeButton">
	<img src="https://images-na.ssl-images-amazon.com/images/I/41ft-avvlhL.jpg" alt="bell">
	<div id="subscribeButtonText">Subscribe for Inventory Notifications</div>
</div>

更新的关键帧代码:

@keyframes shake {
    0%,
    100% {
        transform: rotate(0deg);
    }
    10%,
    40% {
        transform: rotate(6deg);
    }
    40%,
    60% {
        transform: rotate(0deg);
    }
    60%,
    90% {
        transform: rotate(-6deg);
    }
}

【问题讨论】:

    标签: css css-animations keyframe


    【解决方案1】:

    您的关键帧规则有一些拼写错误

    @keyframes shake {
      0%,
      100% {
        transform: rotate(0deg);
      }
      20%,
      60% {
        transform: rotate(6deg);
      }
      40%,
      80% {
        transform: rotate(-6deg);
      }
    }
    

    #subscribeButton {
      width: 50%;
      height: 150px;
      background: #1b8c00;
      background: #5fae4c;
      border: 2px solid #fff;
      cursor: pointer;
    }
    
    #subscribeButton img {
      width: 70px;
      height: auto;
      display: block;
      margin: 10px auto;
      text-align: center;
      animation-name: shake;
      animation-timing-function: ease-in-out;
      animation-duration: .5s;
      animation-iteration-count: 2;
      animation-delay: .5s;
    }
    
    @keyframes shake {
      0%,
      100% {
        transform: rotate(0deg);
      }
      20%,
      60% {
        transform: rotate(6deg);
      }
      40%,
      80% {
        transform: rotate(-6deg);
      }
    }
    <div id="subscribeButton">
      <img src="https://images-na.ssl-images-amazon.com/images/I/41ft-avvlhL.jpg" alt="bell">
    
    </div>

    【讨论】:

    • 谢谢! -web-kit 不再需要了吗?知道为什么我的迭代计数不起作用吗?
    • 我将演示的迭代次数更改为无限,但 2 也可以。演示已更新...不再需要 webkit 前缀。
    • 谢谢。如果我将迭代设置为 2,我将如何在动画之间出现延迟?
    • 您不会延迟执行此操作,而是调整百分比,使其实际上是两个动画合二为一。
    • 我刚刚在我的问题中添加了新的关键帧代码。我不完全确定如何执行您所说的。我试过的没有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 2013-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多