简体   繁体   English

网页动画在结束后恢复

[英]Web animation reverts back after ends

I have a question regarding the browser compatability of Web Animations. 我有一个关于Web动画的浏览器兼容性的问题。 I am aware that it is not working on some browsers. 我知道它不适用于某些浏览器。

However, is it possible to still use the transformation that is normally applied by the animation. 但是,是否仍然可以使用动画通常应用的变换。 My animation runs (through neon-animation from Polymer), but the result doesn't stay. 我的动画运行(通过Polymer的neon-animation ),但结果不会停留。 It reverts back when the animation is finished. 它在动画结束时恢复。

(Small note, the $$("paper-item") is from polymer and is equivalent to querySelector("paper-item") ) (小注意, $$("paper-item")来自聚合物,相当于querySelector("paper-item")

I fixed this on Chrome with the following code: 我使用以下代码在Chrome上修复此问题:

     _onNeonAnimationFinish: function() {
        if (this.opened) {
           this.$$("paper-item").style.margin = '16px auto';
           this.$$("paper-item").style.width = '84vw';
           this.$$("paper-item").style.height = '144px';
        } else {
           this.$$("paper-item").style.margin = "0px auto";
           this.$$("paper-item").style.width = '72vw';
           this.$$("paper-item").style.height = '72px';
        }
     }

As said, this is working on Chrome. 如上所述,这适用于Chrome。 Firefox and Safari are having trouble with it though. Firefox和Safari虽然遇到了麻烦。 How can this be fixed? 怎么解决这个问题?

My complete code is as following: 我的完整代码如下:

<!--  Custom element -->
<dom-module id="agenda-item">
   <template>
      <style>
         paper-item {
            background-color: #ffffff;
            width: 72vw;
            margin: 0 auto;
            height: 72px;
         }
      </style>


      <paper-item>
         - content -
      </paper-item>

   </template>
   <script>
      Polymer({
         is: 'agenda-item',
         behaviors: [
            Polymer.NeonAnimationRunnerBehavior
         ],
         properties: {
            opened: {
               type: Boolean,
               value: false,
               reflectToAttribute: true
            },
            animationConfig: {
               value: function() {
                  return {
                     'expand': [{
                        name: 'expand-list-item-animation',
                        node: this.$$("paper-item"),
                        timing: {
                           duration: 1000
                        }
                     }],
                     'collapse': [{
                        name: 'collapse-list-item-animation',
                        node: this.$$("paper-item"),
                        timing: {
                           duration: 1000
                        }
                     }]
                  };
               }
            }
         },
         listeners: {
            'tap': 'onClick',
            'neon-animation-finish': '_onNeonAnimationFinish'
         },
         onClick: function(event) {
            if (this.opened) {
               this.collapse();
            } else {
               this.expand();
            }
         },
         expand: function() {
            this.cancelAnimation();
            this.playAnimation('expand');
            this.opened = true;
         },
         collapse: function() {
            this.cancelAnimation();
            this.opened = false;
            this.playAnimation('collapse');
         },
         _onNeonAnimationFinish: function() {
            if (this.opened) {
               this.$$("paper-item").style.margin = '16px auto';
               this.$$("paper-item").style.width = '84vw';
               this.$$("paper-item").style.height = '144px';
            } else {
               this.$$("paper-item").style.margin = '0px auto';
               this.$$("paper-item").style.width = '72vw';
               this.$$("paper-item").style.height = '72px';
            }
         }
      });
   </script>
</dom-module>



<!--  Custom animation -->
<!--  Both custom animations have the same idea and similar code  -->
<script>
   Polymer({

      is: 'expand-list-item-animation',

      behaviors: [
         Polymer.NeonAnimationBehavior
      ],

      configure: function(config) {
         var node = config.node;

         if (config.transformOrigin) {
            this.setPrefixedProperty(node, 'transformOrigin', config.transformOrigin);
         }

         this._effect = new KeyframeEffect(node, [{
            offset: 0.0,
            'margin': '0 auto',
            'width': '72vw',
            'height': '72px'
         }, {
            offset: 0.6,
            'margin': '16px auto',
            'width': '84vw',
            'height': '72px'
         }, {
            offset: 1.0,
            'margin': '16px auto',
            'width': '84vw',
            'height': '144px'
         }], this.timingFromConfig(config));

         return this._effect;
      }

   });
</script>

EDIT: I found the problem, but not how to solve it. 编辑:我发现了问题,但没有找到解决方法。 It would be great to get some help. 得到一些帮助会很棒。

The neon-animation-finish is not called at the moment the animation finishes . 动画结束时不会调用霓虹动画完成 It is called just before that (not on chrome btw). 它就在那之前调用(不是在chrome btw上)。 Then, when the function is called to adjust the styling, it is overwritten by the animation. 然后,当调用该函数来调整样式时,它将被动画覆盖。

You need to define a listener to the animation-finish and define what you want to see when the animation has finished like this: 您需要为动画完成定义一个侦听器,并定义动画完成后要查看的内容,如下所示:

listeners: {
// this event is fired when the animation finishes
'neon-animation-finish': '_onNeonAnimationFinish'

}, },

Have a look at the Polymer documentation at: https://github.com/PolymerElements/neon-animation/blob/master/README.md 请查看Polymer文档: https//github.com/PolymerElements/neon-animation/blob/master/README.md

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

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