首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >控制CSS动画计数表单输入

控制CSS动画计数表单输入
EN

Stack Overflow用户
提问于 2018-04-04 16:37:06
回答 2查看 92关注 0票数 0

我一直在努力控制每分钟下降的速度。是否可以根据Drops in each minute:输入来控制下降的速度?就像输入值为60一样,每分钟将有60个水滴(animation: drop 1s)。实现这一目标的最佳方式是什么?提前谢谢你的建议。

篡改到代码的链接是这里

代码语言:javascript
复制
body {
  background: #e8e5ea;
}

.wrap {
  position: absolute;
  width: 100px;
  height: 200px;
  left: 50%;
  margin-left: -50px;
  top: 50%;
  margin-top: -100px;
}

.drop {
  width: 40px;
  height: 40px;
  left: 50%;
  margin-left: -20px;
  position: absolute;
  animation: drop 2s cubic-bezier(0.55, 0.085, 0.68, 0.53) 0s infinite;
}

.drop circle {
  fill: #2a96ed;
}

.drop-outer {
  position: absolute;
  box-sizing: border-box;
  /* border: 1px solid #333; */
  width: 100px;
  height: 200px;
  overflow: hidden;
  border-bottom-right-radius: 50px;
  border-bottom-left-radius: 50px;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
  background-clip: padding-box;
  -webkit-mask-image: -webkit-radial-gradient(circle, white 100%, black 100%);
}

.ripple {
  position: absolute;
  box-sizing: border-box;
  width: 240px;
  height: 240px;
  top: 68px;
  left: -70px;
  perspective: 100;
  transform: rotateX(65deg);
}

.ripple .ripple-svg {
  position: absolute;
  width: 240px;
  height: 240px;
  opacity: 0;
}

.ripple .ripple-svg circle {
   fill: none;
   stroke: #2a96ed;
   stroke-width: 10px;
   stroke-alignment: inner;
}

.ripple-1 {
  animation: ripple 2s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0s infinite;
}

.ripple-1 .ripple-svg {
  animation: fade-in-out 2s linear 0s infinite;
}

.ripple-1 .ripple-svg circle {
  animation: border 2s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0s infinite;
}

.ripple-2 {
  animation: ripple 2s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.2s infinite;
}

.ripple-2 .ripple-svg {
  animation: fade-in-out 2s linear 0.2s infinite;
}

.ripple-2 .ripple-svg circle {
  animation: border 2s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.2s infinite;
}

.ripple-3 {
  animation: ripple 2s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.35s infinite;
}

.ripple-3 .ripple-svg {
  animation: fade-in-out 2s linear 0.35s infinite;
}

.ripple-3 .ripple-svg circle {
  animation: border 2s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.35s infinite;
}



@keyframes drop {
  0% {
    transform: scale3d(0.01,0.01,0.01) translateY(0)
  }
  10% {
    transform: scale3d(1,1,1) 
  }
  44% {
    transform: scale3d(1,1,1) translateY(200px)
  }
  100% {
    transform: scale3d(1,1,1) translateY(200px)
  }
}

@keyframes fade-in-out {
  0% {opacity: 0}
  42% {opacity: 0}
  52% {opacity: 1}
  65% {opacity: 1}
  100% {opacity: 0}
}

@keyframes ripple {
  0% { transform: rotateX(65deg) scale3d(0.2, 0.2, 0.2) }
  42% { transform: rotateX(65deg) scale3d(0.2, 0.2, 0.2) }
  100% { transform: rotateX(65deg) scale3d(0.9, 0.9, 0.9) }
}

@keyframes border {
  0% { stroke-width: 6px }
  42% { stroke-width: 6px }
  100% {stroke-width: 2px }
}
代码语言:javascript
复制
Drops in each minute: <input type="number" id="number"/><br>

<div class="wrap">
  <div class="drop-outer">
    <svg class="drop" viewBox="0 0 40 40" version="1.1"
    xmlns="http://www.w3.org/2000/svg">
    <circle cx="20" cy="20" r="20"/>
    </svg>
  </div>
  <div class="ripple ripple-1">
      <svg class="ripple-svg" viewBox="0 0 60 60" version="1.1"
    xmlns="http://www.w3.org/2000/svg">
    <circle cx="30" cy="30" r="24"/>
      </svg>
  </div>
  <div class="ripple ripple-2">
      <svg class="ripple-svg" viewBox="0 0 60 60" version="1.1"
    xmlns="http://www.w3.org/2000/svg">
    <circle cx="30" cy="30" r="24"/>
      </svg>
  </div>
  <div class="ripple ripple-3">
      <svg class="ripple-svg" viewBox="0 0 60 60" version="1.1"
    xmlns="http://www.w3.org/2000/svg">
    <circle cx="30" cy="30" r="24"/>
      </svg>
  </div>
</div>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-04-04 16:49:35

只有当您通过JavaScript指定相关的样式时。

您的示例相当复杂,并不是真正的极小,因此下面是一个简单的示例,它展示了这个想法:

代码语言:javascript
复制
const animateInner = document.querySelector('#animate .inner');
const input = document.querySelector('input');

document.querySelector('button').addEventListener('click', function() {
  console.log('update to', `${input.value || 0}s`);
  animateInner.style.animationDuration = `${input.value || 0}s`;
});
代码语言:javascript
复制
#animate {
  position: relative;
  width: 200px;
  height: 200px;
  border: 1px solid #000;
}

#animate .inner {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #F00;
  animation-name: fill;
  animation-iteration-count: infinite;
}

@keyframes fill {
  from {
    top: 100%;
  }

  to {
    top: 0;
  }
}
代码语言:javascript
复制
<label>Duration in seconds: <input /></label>
<button>Update</button>
<div id="animate"><div class="inner"></div></div>

简而言之,您需要控制“动画持续时间”属性。这将影响其发生的速度。因为你想要“每分钟下降”,你必须做一些数学来把它转换成一个持续时间。

因为您的动画看起来有几件事情是一致工作的,所以您需要同时更新它们。

票数 1
EN

Stack Overflow用户

发布于 2018-04-04 17:15:00

所以你可以用

属性的animation-iteration-count CSS3属性,其秘诀是获取该数字并更新css。

代码语言:javascript
复制
$(function(){
    $('#number').on('change', function(){
    var count = $(this).val();    
    $('.drop').css('animation-iteration-count', count);
    $('.ripple-1').css('animation-iteration-count', count);
    $('.ripple-1 .ripple-svg').css('animation-iteration-count', count);
    $('.ripple-1 .ripple-svg circle').css('animation-iteration-count', count);    
    $('.ripple-2').css('animation-iteration-count', count);
    $('.ripple-2 .ripple-svg').css('animation-iteration-count', count);
    $('.ripple-2 .ripple-svg circle').css('animation-iteration-count', count); 
    $('.ripple-3').css('animation-iteration-count', count);
    $('.ripple-3 .ripple-svg').css('animation-iteration-count', count);
    $('.ripple-3 .ripple-svg circle').css('animation-iteration-count', count);     
  });
});

JSfiddle

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49656163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档