简体   繁体   English

在一个动画和另一个动画之间切换。 Angular.js

[英]Toggle between one animation and another. Angular.js

I have 2 animations called "prev" and "next". 我有2个称为“上一个”和“下一个”的动画。 When you click on the prev button, the "prev" animation should be executed, when you click on the "next" button the "next" animation should be executed. 当您单击上一个按钮时,应执行“上一个”动画;当您单击“下一个”按钮时,应执行“下一个”动画。 I'm using ng-class to try to log it. 我正在使用ng-class尝试记录它。 How can I do it? 我该怎么做?

    <div ng-controller="MyCtrl">
      <div class='contendor_portafolio' class='next'>
        <video  id='video' width="320" height="240" ng-class='transition' controls>
            <source src="video.mp4" type="video/mp4" />
        </video>
      </div>
      <button ng-click="fn_transicion('next')">next</button>
      <button ng-click="fn_transicion('prev')">prev</button>

    </div>

  var myApp = angular.module('myApp',[]);

  function MyCtrl($scope) {
    $scope.fn_transicion= function(transition){

        if(transition=='prev'){
           $scope.transition="prev";
        }
        if(transition=='next'){
           $scope.transition="next";
        }
    }
  }

  #video{
     width: 98%;
     height: 100%;
     transition: all linear 0.5s;
     background:blue;
     -webkit-animation: next 1s 1; /* Safari 4+ */
  }

  @-webkit-keyframes prev {
     25% { 
        -webkit-transform: translateX(-1700px);
     }
     50% { 
        opacity: 0;
        -webkit-transform: translateY(2000px);
        display: none;
     }
     60% { 
        -webkit-transform: translateX(1700px);
     }
     100%{
     } 
  }


  @-webkit-keyframes next {
     25% { 
        -webkit-transform: translateX(1700px);
     }
     50% { 
        opacity: 0;
        -webkit-transform: translateY(-2000px);
        display: none;
     }
     60% { 
        -webkit-transform: translateX(-1700px);
     }
     100%{
     } 
  }

http://jsfiddle.net/752ffz1u/ http://jsfiddle.net/752ffz1u/

Your answer is pretty close to the solution. 您的答案非常接近解决方案。 The AngularJs part's working fine but the problem is you defined the animation keyframes, but not attached them to the corresponding classes (that are toggled via transition variable and ng-class). AngularJs部分工作正常,但问题是您定义了动画关键帧,但没有将它们附加到相应的类(通过过渡变量和ng-class进行切换)。

Add these lines to your css code will solve the problem: 将这些行添加到您的CSS代码中即可解决问题:

 #video.next {
   -webkit-animation: next 1s 1; /* Safari 4+ */
 }

 #video.prev {
   -webkit-animation: prev 1s 1; /* Safari 4+ */
 }

Also, you can remove 另外,您可以删除

-webkit-animation: next 1s 1; /* Safari 4+ */

from the #video { } block. 来自#video {}块。

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

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