CSS 动画在 Chrome 中不起作用

2024-03-03

对项目的一些见解: 一个完整的交互式网站,动画将在其中播放..然后它们会停止,一旦它们停止并且动画上发生鼠标悬停事件,它将播放直到动画完成 70%,当单击另一个对象时(在本例中)案例文本)它将完成它的循环。

我的项目合作伙伴在 Google Web Designer 中制作了动画,我们为我们的项目尝试了多种程序,例如 Adob​​e Edge,但不幸的是,由于动画的大小,我们无法使用 SVG 或 PNG 序列,精灵表也是如此..所以我们到达了CSS动画,不幸的是我对CSS动画的了解非常有限,我想知道是否有人能够帮助我。

我有一个问题:为什么我的 CSS 动画在 Chrome 中的表现与在 Firefox 中的表现不同?

我尝试了以下解决方案并查看了以下帖子:

  1. css3 动画在 Chrome 中不起作用 https://stackoverflow.com/questions/12265096/css3-animation-not-working-in-chrome
  2. CSS 动画在 Chrome 上不起作用 https://stackoverflow.com/questions/21939736/css-animation-not-working-on-chrome
  3. Chrome 关键帧动画不起作用 https://stackoverflow.com/questions/25003675/chrome-keyframe-animation-not-working

jquery:

<script>
$(document).ready(function(){
    //$('.gwd-img-r1sa').toggle(function () {
    //    $('.gwd-img-r1sa').css({"animation-play-state":"paused","-webkit-animation-play-state":"paused"});
    //}, function () {
    //    $('.gwd-img-r1sa').css({"animation-play-state":"running","-webkit-animation-play-state":"running"});
    //});

    $(".gwd-img-r1sa").on("mouseenter", function(){
        $(".gwd-img-r1sa").css({"animation-iteration-count":"0.7", "-webkit-animation-iteration-count":"0.9"});
    });

    $("#play").on("click", function(){
        $(".gwd-img-r1sa").css({"animation-iteration-count":"1", "-webkit-animation-iteration-count":"1"});
    });

});

</script>

css:

<style type="text/css">

    /**.gwd-img-r1sa:hover, .gwd-img-r1sa:focus
{
    -webkit-animation-play-state: paused;
    animation-play-state: paused;
}
**/

html, body {
  width: 100%;
  height: 100%;
  margin: 0px;
}

body {
  background-color: transparent;
  -webkit-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  -moz-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  -webkit-perspective: 1400px;
  -moz-perspective: 1400px;
  perspective: 1400px;
  -webkit-transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

.gwd-img-r1sa {
  position: absolute;
  width: 192px;
  height: 146px;
  -webkit-transform-origin: 50% 50%;
  -moz-transform-origin: 50% 50%;
  transform-origin: 50% 50%;
  -webkit-transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;
  transform-style: preserve-3d;
  left: 312px;
  top: 604px;
  -webkit-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  -moz-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
}

@-webkit-keyframes gwd-empty-animation {
  0% { opacity: 0.001; }
  100% { opacity: 0; }
}
@-moz-keyframes gwd-empty-animation {
  0% { opacity: 0.001; }
  100% { opacity: 0; }
}
@keyframes gwd-empty-animation {
  0% { opacity: 0.001; }
  100% { opacity: 0; }
}
@-webkit-keyframes gwd-gen-hlergwdanimation_gwd-keyframes {
  0% { left: 312px; top: 604px; -webkit-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); -webkit-animation-timing-function: linear; }
  30% { left: 595px; top: 350px; -webkit-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); -webkit-animation-timing-function: linear; }
  50% { left: 595px; top: 350px; -webkit-transform: matrix3d(0.0510417556, 0.9986965201, 0, 0, -0.9986965201, 0.0510417556, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); -webkit-animation-timing-function: linear;}
  100% { left: 595px; top: 350px; -webkit-transform: matrix3d(0.051, 0.9987, 0, 0, -0.9987, 0.051, 0, 0, 0, 0, 1, 0, 312, 146, 0, 1); -webkit-animation-timing-function: linear; }
}
@-moz-keyframes gwd-gen-hlergwdanimation_gwd-keyframes {
  0% { left: 312px; top: 604px; -moz-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); -moz-animation-timing-function: linear; }
  30% { left: 595px; top: 350px; -moz-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); -moz-animation-timing-function: linear; }
  50% { left: 595px; top: 350px; -moz-transform: matrix3d(0.0510417556, 0.9986965201, 0, 0, -0.9986965201, 0.0510417556, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); -moz-animation-timing-function: linear; }
  100% { left: 595px; top: 350px; -moz-transform: matrix3d(0.051, 0.9987, 0, 0, -0.9987, 0.051, 0, 0, 0, 0, 1, 0, 312, 146, 0, 1); -moz-animation-timing-function: linear; }
}
@keyframes gwd-gen-hlergwdanimation_gwd-keyframes {
  0% { left: 312px; top: 604px; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); animation-timing-function: linear; }
  30% { left: 595px; top: 350px; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); animation-timing-function: linear; }
  50% { left: 595px; top: 350px; transform: matrix3d(0.0510417556, 0.9986965201, 0, 0, -0.9986965201, 0.0510417556, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); animation-timing-function: linear; }
  100% { left: 595px; top: 350px; transform: matrix3d(0.051, 0.9987, 0, 0, -0.9987, 0.051, 0, 0, 0, 0, 1, 0, 312, 146, 0, 1); animation-timing-function: linear; }
}
body .gwd-gen-hlergwdanimation {
  -webkit-animation: gwd-gen-hlergwdanimation_gwd-keyframes 3s linear 0s 1 normal forwards;
  -moz-animation: gwd-gen-hlergwdanimation_gwd-keyframes 3s linear 0s 1 normal forwards;
  animation: gwd-gen-hlergwdanimation_gwd-keyframes 3s linear 0s 1 normal forwards;
}

</style>

html:

    <img src="3ds_preset_gearshape.png" class="gwd-img-r1sa gwd-gen-hlergwdanimation" data-gwd-style="" data-gwd-override-style="" style="animation-iteration-count: 0.1;">


<div id="play">
    click here to play
</div>

有人可以帮忙吗?

另外:为什么图像会移动,然后停止......然后悬停时有时会跳到 30%,而不是播放到 30%?跳到 70% 而不是玩到 70% 也是同样的情况吗?

刚刚发现了一些值得注意的事情:

改变:<img src="3ds_preset_gearshape.png" class="gwd-img-r1sa gwd-gen-hlergwdanimation" data-gwd-style="" data-gwd-override-style="" style="animation-iteration-count: 0.1;">

对此:<img src="3ds_preset_gearshape.png" class="gwd-img-r1sa gwd-gen-hlergwdanimation" data-gwd-style="" data-gwd-override-style="" style="-webkit-animation-iteration-count: 0.1;">

导致这部分动画在 Chrome 中工作,但是为什么当我在文档的样式部分中使用它时它不起作用?


首先:你的 jQuery 有一个错误。改变-webkit-animation-iteration-count从 0.9 到 0.7。另外,请看一下:http://caniuse.com/#search=animation http://caniuse.com/#search=animation。您可以看到,您必须为 google chrome 使用前缀“-webkit”。这就是为什么,您需要在 img 样式标签中定义这两个内容。就像这样:

<img src="3ds_preset_gearshape.png" class="gwd-img-r1sa gwd-gen-hlergwdanimation" data-gwd-style="" data-gwd-override-style="" style="animation-iteration-count: 0.1;-webkit-animation-iteration-count: 0.1;">

更好的方法是在样式表中定义迭代计数,而不是在 html 中。如果您需要不同的 img 进行不同的迭代计数,那么这当然对您来说不是一个好的解决方案。否则改变:

3s linear 0s 1 normal forwards 

to

3s linear 0s 0.1 normal forwards

并留下style在img标签空白处

对于您问题的停止和播放部分:

jsfiddle.net/Lvq6ee8d/14/ http://jsfiddle.net/Lvq6ee8d/14/

解释一下:你知道你的动画运行3秒,所以我设置了一个超时函数,该函数在触发“animationstart”事件时启动。然后在 300ms(3000ms/100*10 = 300ms) 后,animationplaystate 设置为暂停。所以 10% 后,动画停止。悬停时,动画继续。另请记住,在本例中我们需要稍微更改一下 css。我们将动画迭代设置为所需的数量,即我们希望动画完成时的位置(在我的示例中为 1),因此我们可以使用暂停并运行它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CSS 动画在 Chrome 中不起作用 的相关文章

随机推荐

  • IIS 会话超时与 ASP.NET 会话超时

    在 IIS 6 以及其他版本 中 属性 gt 主目录选项卡 gt 配置按钮 gt 选项选项卡中有一个会话超时设置 看起来像这样 在 ASP NET web config 中有一个 SessionState 设置 如下所示
  • iOS 如何合并两个mp3文件?

    我的应用程序中有一个用户录音和另一个 mp3 文件 我希望用户能够将这两个文件作为一个导出 这意味着这两个文件将以某种方式合并或相互叠加 如果不明白的话 这两个 mp3 文件将同时播放 就像用户可以通过乐器录制歌曲 例如歌曲 的任何应用程序
  • SQLite 查询问题

    2个问题 首先 在 MSSQL 中 我可以通过执行以下操作将 nvarchar 转换为 datetime cast 5 31 2011 12 00 00 AM as datetime as convertedtodate 结果 2011 0
  • 单击编程按钮会引发“System.StackOverflowException”异常

    我在 C Net 中编写了一个 WinForms 程序 用于以编程方式单击密码表单中的按钮 Form1加载并显示Form2作为对话框 如果 DialogResult 不是 DialogResult OK 则应用程序将关闭 到目前为止我有一个
  • 在具有多个目录的项目结构中使用 Python 单元测试

    我需要使用unittestpython 库来执行有关 3 个函数的测试src arithmetics py文件 这是我的项目结构 src arithmetics py test lcm init py test lcm exception
  • 使用 linq 过滤 List

    我有一个包含 Id 值的 List 对象 例如它包含 1 2 10 1 23 11 1 4 2 2 等我需要找出 1 2 等发生了多少次 在 C 中使用 Linq 请帮忙 使用起来非常简单Enumerable GroupBy http ms
  • 为什么多个等待像 Task.WhenAll() 一样花费相同的时间

    据我了解 当您有任务列表时 建议使用await Task WhenAll 超过多个await 由于这样的方式Task WhenAll 处理异常 然而 根据我对 async await 工作方式的理解 我想知道为什么下面的代码块具有相同的执行
  • 如何在 tidyverse 中转置数据框?

    使用基本的 R 我可以转置数据框 比如说mtcars 其中具有同一类的所有列 as data frame t mtcars 或者用管道 library magrittr mtcars gt t gt as data frame 如何在 ti
  • 在 JQuery AJAX 发布之前暂停

    因为我正在处理的页面是一个内联网页面 所以我的 AJAX 调用和响应非常快 出于可用性目的 我想要短暂的 1 2 秒暂停来显示加载动画 下面是我尝试过的 但动画几乎不可见 document ready function wait hide
  • CSS?这个箭头是怎么做出来的?

    这让我发疯 我一直在使用 Firefox 检查器来尝试找出这个箭头是如何在进展现场 http headwaythemes com 我通过检查器删除块来削减代码 并将其简化为 无论我在哪里检查 我都可以not找到任何这样的形状 没有背景图像
  • windows mingw下使用zlib

    我似乎无法让 zlib 在 Windows 下的 mingw 上执行任何操作 我下载了zlib http sourceforge net projects mingw files beta MinGW zlib zlib 1 2 3 1 m
  • 设计在不同的屏幕上破碎[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我设计了一个网页 其中很少有HTML元素没有响应 这些元素是动态生成的jQuery我相信 应该有一种方法可以让他们看起来反应灵敏 Me
  • 如何针对 TextReader 使用正则表达式?

    在 可能 非常大的文本中查找模式的最佳方法是什么 我可以使用正则表达式 但它接受字符串作为参数 有没有办法将它与 TextReader 或某种流一起使用 不 正则表达式可能需要进行回溯 由于流只能向前读取 这意味着无论如何它都必须将整个流保
  • 无法在 Docker 容器内从 Google API 交换 AccessToken

    我有一个用 Go 编写的网络应用程序 使用 oauth2 包golang org x oauth2 通过 Google 登录用户 按照本教程操作https developers google com identity sign in web
  • Facebook API - uids 和电子邮件 [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我正在尝试开发一个应用程序 用户 X 已登录 Facebook 应用程序有一组电子邮件地址 可能是用户 X 的朋友 应用程序获取用户
  • 为什么要在 Objective C 构造函数中使用 [super init]?

    假设我有一个名为 Item 的类 它是 NewsItem 和 TwitterItem 的超类 如果我想创建一些 NewsItem 我必须使用 在构造函数内 self super init 如果是 为什么 在 Java C 中我会这样做 Ne
  • Flexbox 实现水平滚动

    我正在使用 Flexbox 布局制作一个购物中心网站 但 Flexbox 在某些区域会导致问题 Flexbox 似乎在某些区域进行水平滚动 但我不希望这样 您的问题是横幅中的图像太宽 无法适应大多数视口 因此它们迫使页面变宽 没有简单的方法
  • 在 R 中重复多个 NULL

    在我的模拟中 我需要一个如下所示的向量 vec NULL NULL NULL NULL 2 2 2 2 4 4 4 4 但是 在 R 中 当我使用rep NULL 4 它什么也不返回 例如 vec all c rep NULL 4 rep
  • SwiftUI 垂直未对齐的文本

    我有一些垂直未对齐的文本 我不知道为什么 代码 struct IBANInputView View State var securityDigits State var bankCode State var accountNumber va
  • CSS 动画在 Chrome 中不起作用

    对项目的一些见解 一个完整的交互式网站 动画将在其中播放 然后它们会停止 一旦它们停止并且动画上发生鼠标悬停事件 它将播放直到动画完成 70 当单击另一个对象时 在本例中 案例文本 它将完成它的循环 我的项目合作伙伴在 Google Web