简体   繁体   English

CSS动画在Chrome中不起作用

[英]CSS Animation not working in Chrome

Some insight into the project: A full interactive website, where animations will play.. then they'll stop, once they've stopped and a mouseover event on an animation occurs it will play until 70% of the animation is complete, when clicking on another object (in this case text) it will complete it's cycle. 对项目的一些了解:一个完整​​的交互式网站,将在其中播放动画..然后它们将停止,一旦它们停止并且发生动画上的鼠标悬停事件,它将一直播放到动画完成70%(单击时)。在另一个对象(在本例中为文本)上,它将完成循环。

My project partner made the animation in Google web designer, we've tried multiple programs for our project such as Adobe Edge, but unfortunately due to the size of our animations we are unable to use SVG or PNG sequences, and the same goes for spritesheets.. so we arrived at css animations, unfortunately my knowledge of css animations is quite limited and I was wondering if anyone would be able to help me out. 我的项目合作伙伴使用Google Web Designer制作了动画,我们为该项目尝试了多个程序,例如Adobe Edge,但是不幸的是,由于动画的大小,我们无法使用SVG或PNG序列,子画面也是如此..所以我们来到了CSS动画,很遗憾,我对CSS动画的了解非常有限,我想知道是否有人可以帮助我。

I have a problem: why doesn't my CSS animation act the same in Chrome as in Firefox? 我有一个问题:为什么我的CSS动画在Chrome浏览器中的作用与在Firefox中不同?

I've tried the following solutions and looked at the following posts: 我尝试了以下解决方案,并查看了以下帖子:

  1. css3 animation not working in chrome CSS3动画无法在Chrome中使用
  2. CSS Animation not working on Chrome CSS动画无法在Chrome上运行
  3. Chrome Keyframe animation not working Chrome关键帧动画不起作用

jquery: 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: 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: 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>

Can someone please help? 有人可以帮忙吗?

Also: Why does the image move, then stop.. then on hover it sometimes skips to 30% instead of playing until 30%? 另外:为什么图像会移动,然后停止..然后在悬停时有时会跳到30%而不是播放到30%? the same goes for skipping to 70% instead of playing until 70%? 跳到70%而不是一直玩到70%一样吗?

Just found something that could be note worthy: 刚刚发现了一些值得注意的东西:

Changing: <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="animation-iteration-count: 0.1;">

to this: <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;"> 为此: <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;">

causes this bit of the animation to work in Chrome, but why didn't it work when I had this in the styles segment of my document? 使动画的这一部分在Chrome中起作用,但是当我在文档的样式部分中使用动画时,为什么动画不起作用?

Firstly: Your jQuery has a mistake in it. 首先:您的jQuery有一个错误。 Change the -webkit-animation-iteration-count from 0.9 to 0.7. -webkit-animation-iteration-count从0.9更改为0.7。 Also, please take a look at: http://caniuse.com/#search=animation . 另外,请查看: http : //caniuse.com/#search=animation You can see, that you have to use the prefix "-webkit" for google chrome. 您会看到,对于Google chrome,必须使用前缀“ -webkit”。 That is why, you need to define both of it in your img style tag. 因此,您需要在img样式标签中同时定义它们。 Like so: 像这样:

<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;">

A better way to do this, would be to define the iteration count in your stylesheet, not in the html. 更好的方法是在样式表中而不是在html中定义迭代计数。 If you need different iteration counts for different img's, then this is not a good solution for you, ofcourse. 如果对于不同的img需要不同的迭代次数,那么这当然不是一个好的解决方案。 Otherwise change: 否则更改:

3s linear 0s 1 normal forwards 

to

3s linear 0s 0.1 normal forwards

And leave the style in the img tags blank 并将img标签中的style保留为空白

For the stop and play part of your question: 对于您的问题,停下来玩一下:

jsfiddle.net/Lvq6ee8d/14/ jsfiddle.net/Lvq6ee8d/14/

For explanation: You know that your animation runs 3 seconds, so I have set a timeout function, which starts when the event "animationstart" is being triggered. 作为说明:您知道动画运行了3秒钟,所以我设置了超时功能,该超时功能在触发“ animationstart”事件时启动。 Then after 300ms(3000ms/100*10 = 300ms) the animationplaystate is set to pause. 然后在300ms(3000ms / 100 * 10 = 300ms)之后,动画播放状态将设置为暂停。 So after 10%, the animation stops. 因此,在10%之后,动画将停止。 And on hover, the animation continues. 悬停时,动画继续。 Also keep in mind, that in this example we need to change the css a little bit. 还请记住,在此示例中,我们需要稍微更改css。 We set the animation iteration to the desired amount, where we want the animation to be when it's finished(1 in my example), so we can use pause and running on it. 我们将动画迭代设置为所需的数量,即希望动画完成时的位置(在本示例中为1),因此我们可以使用暂停并在其上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM