运行JavaScript以使用CSS关键帧更新HTML并重播计数动画时出现的问题

如何解决运行JavaScript以使用CSS关键帧更新HTML并重播计数动画时出现的问题

我正在尝试使用HTML / CSS和Javascript / JQuery构建一个简单的Web应用程序,该应用程序的数量为10,并设置动画并依次显示数字。我的动画效果很好,但是我无法找出使用JQuery在Javascript中更新和重新运行动画的最佳方法

我只希望程序运行动画“ grow-number”,然后对h1 .anim标签中的数字进行迭代,然后为每个数字从1到10依次显示相同的动画,以便浏览器将显示动画的计数序列。

我尝试使用setInterval并使用回调,但是我肯定做错了,因此我不会在代码包括这些失败。

* {
  margin: 0;
  padding: 0;
  Box-sizing: border-Box;
}

html {
  font: normal 200px sans-serif;
  font-family: 'Quicksand',sans-serif;
  color: orange;
}

.content-area {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  background-color: green;
  min-height: 100vh;
  /*opacity:0%;*/
}

.anim {
  transform: scale(0);
  opacity: 0;
  
  /*this animation SHOULD PROBABLY be called with javascript
  or jquery but I have NOT had any luck getting it to work and 
  iterating throug the numbers.  I uncommented here just to show 
  what it looks like in general*/
 
  animation: grow-number 4s 2s 10;
  /*animation-duration:4s;
    animation-name: grow-number;
    animation-delay:2s;
    animation-iteration-count:10;*/
}

@keyframes grow-number {
  0% {
    transform: scale(0);
    opacity: 0%;
  }
  10% {
    opacity: 100%;
  }
  19% {
    transform: scale(2.25);
    color: orange;
  }
  20% {
    transform: scale(2);
    color: blue;
  }
  80% {
    transform: scale(2);
    color: blue;
  }
  90% {
    opacity: 100%;
    color: orange;
  }
  100% {
    transform: scale(0);
    color: orange;
    opacity: 0%;
  }
}
<!DOCTYPE html>
<html>

<head>
  <title>Count to 10!</title>
  <!--jquery-->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script>
    //this needs to iterate and rerun the grow-number animation
    $(".anim").text(1);
    $(".anim").css({
      'animation': 'grow-number 4s 2s'
    });
  </script>
  <!--Font-->
  <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@600&display=swap" rel="stylesheet">

  <!--STYLESHEETS-->
  <link rel="stylesheet" href="countingdemo.css">
</head>

<body>
  <div class="content-area">
    <h1 class="anim">0</h1>
  </div>
</body>

</html>

有人可以通过可用的javascript / jquery代码帮助我。

解决方法

请尝试这个

请稍等我调整计数之间的动画延迟。

TreeViewItem
<TreeView.ItemContainerStyle>
   <Style TargetType="{x:Type TreeViewItem}"
          BasedOn="{StaticResource {x:Type TreeViewItem}}">
      <Setter Property="Tag" Value="{Binding DataContext,RelativeSource={RelativeSource AncestorType={x:Type TreeView}}}"/>
      <Setter Property="ContextMenu">
         <Setter.Value>
            <ContextMenu>
               <MenuItem Header="Sil"
                         Command="{Binding PlacementTarget.Tag.DeleteFolderCommand,RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                         CommandParameter="{Binding}"></MenuItem>
            </ContextMenu>
         </Setter.Value>
      </Setter>
   </Style>
</TreeView.ItemContainerStyle>
$('.anim').each(function () {
  $(this).prop('Counter',0).animate({
      Counter: 10
  },{
      duration: 40000,step: function (now) {
          $(this).text(Math.ceil(now));
      }
  });
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?