AngularJS Material Slide Left to Right CSS3 Animation











up vote
0
down vote

favorite












I am trying to "translate" this AngularJS slide left / right example to an AngularJS Material one.



The latter link consists of the following code snippets:



HTML code:



<div ng-controller="ExampleController" ng-app="switchExample">
<!--<select ng-model="slide" ng-options="item as item.name for item in slides">
</select>-->
<code>slide={{slide}}</code>
<code>moveToLeft={{mtl}}</code>
<md-button ng-click="prev()"><</md-button>
<md-button ng-click="next()">></md-button>
<div class="">
<div class="ngSwitchItem" ng-if="slide.name == 'first'" ng-class="{'moveToLeft' : mtl}">
<div class="firstPage page" md-swipe-left="selectPage(1)">
first
</div>
</div>
<div class="ngSwitchItem" ng-if="slide.name == 'second'" ng-class="{'moveToLeft' : mtl}">
<div class="secondPage page" md-swipe-right="selectPage(0)" md-swipe-left="selectPage(2)">
second
</div>
</div>
<div class="ngSwitchItem" ng-if="slide.name == 'third'" ng-class="{'moveToLeft' : mtl}">
<div class="thirdPage page" md-swipe-right="selectPage(1)" md-swipe-left="selectPage(3)">
third
</div>
</div>
<div class="ngSwitchItem" ng-if="slide.name == 'fourth'" ng-class="{'moveToLeft' : mtl}">
<div class="fourthPage page" md-swipe-right="selectPage(2)">
fourth
</div>
</div>
</div>
</div>


JS code



(function(angular) {
'use strict';
angular.module('switchExample', ['ngMaterial', 'ngAnimate'])
.controller('ExampleController', ['$scope', function($scope) {

$scope.slides = [
{ index: 0, name: 'first' },
{ index: 1, name: 'second' },
{ index: 2, name: 'third' },
{ index: 3, name: 'fourth' }
];
$scope.selectPage = selectPage;
/**
* Initialize with the first page opened
*/
$scope.slide = $scope.slides[0];

$scope.prev = () => {
if ($scope.slide.index > 0) {
selectPage($scope.slide.index - 1);
}
}

$scope.next = () => {
if ($scope.slide.index < 3) {
selectPage($scope.slide.index + 1);
}
}

/**
* @name selectPage
* @desc The function that includes the page of the indexSelected
* @param indexSelected the index of the page to be included
*/
function selectPage(indexSelected) {
if ($scope.slides[indexSelected].index > $scope.slide.index) {
$scope.mtl = false;
} else {
$scope.mtl = true;
}
$scope.slide = $scope.slides[indexSelected];
}
}]);
})(window.angular);


CSS code



body {
overflow-x: hidden;
}

.ngSwitchItem {
position: absolute;
top: 50px;
bottom: 0;
right: 0;
left: 0;

animation-duration: 10.30s;
animation-timing-function: ease-in-out;
-webkit-animation-duration: 10.30s;
-webkit-animation-timing-function: ease-in-out;

}

.page {
position: inherit;
top: 0;
right: inherit;
bottom: inherit;
left: inherit;
}

.firstPage {
background-color: blue;
}

.secondPage {
background-color: red;
}

.thirdPage {
background-color: green;
}

.fourthPage {
background-color: yellow;
}

/* When the page enters, slide it from the right */
.ngSwitchItem.ng-enter {
animation-name: slideFromRight;
-webkit-animation-name: slideFromRight;
}
/* When the page enters and moveToLeft is true, slide it from the left(out of the user view) to the right (left corner) */
.ngSwitchItem.moveToLeft.ng-enter {
animation-name: slideFromLeft;
-webkit-animation-name: slideFromLeft;
}
/* When the page leaves, slide it to left(out of the user view) from the left corner,
in other words slide it from the left(out of the view) to the left corner but in reverse order */
.ngSwitchItem.ng-leave {
animation-name: slideFromLeft;
animation-direction: reverse;
-webkit-animation-name: slideFromLeft;
-webkit-animation-direction: reverse;
}
/* When the page leaves, slide it to the right(out of the user view) from the the left corner,
in other words, slide it from the right but in reverse order */
.ngSwitchItem.moveToLeft.ng-leave {
animation-name: slideFromRight;
animation-direction: reverse;
-webkit-animation-name: slideFromRight;
-webkit-animation-direction: reverse;
}

@keyframes slideFromRight {
0% {
transform: translateX(100%);
}

100% {
transform: translateX(0);
}
}

@keyframes slideFromLeft {
0% {
transform: translateX(-100%);
}

100% {
transform: translateX(0);
}
}

@-webkit-keyframes slideFromRight {
0% {
-webkit-transform: translateX(100%);
}

100% {
-webkit-transform: translateX(0);
}
}

@-webkit-keyframes slideFromLeft {
0% {
-webkit-transform: translateX(-100%);
}

100% {
-webkit-transform: translateX(0);
}
}


As seen, however, the second one doesn't behave as the first one, WHEN slide direction has changed.
For instance:




  1. I slide to left the first one --> second slide loads with the correct animation

  2. Then, I slide to right the second one --> it is supposed the first slide to start appearance from the left side, while the second one to start disappearance to to the right side. Instead, as you may see, the second one start to disappear to the left and from the right side a white slide is shown. At some point, the first slide starts its appearance from the middle of the content.


Please note, I deliberately delay the animations on the second example, just to see the undesired side effect mode clearly.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am trying to "translate" this AngularJS slide left / right example to an AngularJS Material one.



    The latter link consists of the following code snippets:



    HTML code:



    <div ng-controller="ExampleController" ng-app="switchExample">
    <!--<select ng-model="slide" ng-options="item as item.name for item in slides">
    </select>-->
    <code>slide={{slide}}</code>
    <code>moveToLeft={{mtl}}</code>
    <md-button ng-click="prev()"><</md-button>
    <md-button ng-click="next()">></md-button>
    <div class="">
    <div class="ngSwitchItem" ng-if="slide.name == 'first'" ng-class="{'moveToLeft' : mtl}">
    <div class="firstPage page" md-swipe-left="selectPage(1)">
    first
    </div>
    </div>
    <div class="ngSwitchItem" ng-if="slide.name == 'second'" ng-class="{'moveToLeft' : mtl}">
    <div class="secondPage page" md-swipe-right="selectPage(0)" md-swipe-left="selectPage(2)">
    second
    </div>
    </div>
    <div class="ngSwitchItem" ng-if="slide.name == 'third'" ng-class="{'moveToLeft' : mtl}">
    <div class="thirdPage page" md-swipe-right="selectPage(1)" md-swipe-left="selectPage(3)">
    third
    </div>
    </div>
    <div class="ngSwitchItem" ng-if="slide.name == 'fourth'" ng-class="{'moveToLeft' : mtl}">
    <div class="fourthPage page" md-swipe-right="selectPage(2)">
    fourth
    </div>
    </div>
    </div>
    </div>


    JS code



    (function(angular) {
    'use strict';
    angular.module('switchExample', ['ngMaterial', 'ngAnimate'])
    .controller('ExampleController', ['$scope', function($scope) {

    $scope.slides = [
    { index: 0, name: 'first' },
    { index: 1, name: 'second' },
    { index: 2, name: 'third' },
    { index: 3, name: 'fourth' }
    ];
    $scope.selectPage = selectPage;
    /**
    * Initialize with the first page opened
    */
    $scope.slide = $scope.slides[0];

    $scope.prev = () => {
    if ($scope.slide.index > 0) {
    selectPage($scope.slide.index - 1);
    }
    }

    $scope.next = () => {
    if ($scope.slide.index < 3) {
    selectPage($scope.slide.index + 1);
    }
    }

    /**
    * @name selectPage
    * @desc The function that includes the page of the indexSelected
    * @param indexSelected the index of the page to be included
    */
    function selectPage(indexSelected) {
    if ($scope.slides[indexSelected].index > $scope.slide.index) {
    $scope.mtl = false;
    } else {
    $scope.mtl = true;
    }
    $scope.slide = $scope.slides[indexSelected];
    }
    }]);
    })(window.angular);


    CSS code



    body {
    overflow-x: hidden;
    }

    .ngSwitchItem {
    position: absolute;
    top: 50px;
    bottom: 0;
    right: 0;
    left: 0;

    animation-duration: 10.30s;
    animation-timing-function: ease-in-out;
    -webkit-animation-duration: 10.30s;
    -webkit-animation-timing-function: ease-in-out;

    }

    .page {
    position: inherit;
    top: 0;
    right: inherit;
    bottom: inherit;
    left: inherit;
    }

    .firstPage {
    background-color: blue;
    }

    .secondPage {
    background-color: red;
    }

    .thirdPage {
    background-color: green;
    }

    .fourthPage {
    background-color: yellow;
    }

    /* When the page enters, slide it from the right */
    .ngSwitchItem.ng-enter {
    animation-name: slideFromRight;
    -webkit-animation-name: slideFromRight;
    }
    /* When the page enters and moveToLeft is true, slide it from the left(out of the user view) to the right (left corner) */
    .ngSwitchItem.moveToLeft.ng-enter {
    animation-name: slideFromLeft;
    -webkit-animation-name: slideFromLeft;
    }
    /* When the page leaves, slide it to left(out of the user view) from the left corner,
    in other words slide it from the left(out of the view) to the left corner but in reverse order */
    .ngSwitchItem.ng-leave {
    animation-name: slideFromLeft;
    animation-direction: reverse;
    -webkit-animation-name: slideFromLeft;
    -webkit-animation-direction: reverse;
    }
    /* When the page leaves, slide it to the right(out of the user view) from the the left corner,
    in other words, slide it from the right but in reverse order */
    .ngSwitchItem.moveToLeft.ng-leave {
    animation-name: slideFromRight;
    animation-direction: reverse;
    -webkit-animation-name: slideFromRight;
    -webkit-animation-direction: reverse;
    }

    @keyframes slideFromRight {
    0% {
    transform: translateX(100%);
    }

    100% {
    transform: translateX(0);
    }
    }

    @keyframes slideFromLeft {
    0% {
    transform: translateX(-100%);
    }

    100% {
    transform: translateX(0);
    }
    }

    @-webkit-keyframes slideFromRight {
    0% {
    -webkit-transform: translateX(100%);
    }

    100% {
    -webkit-transform: translateX(0);
    }
    }

    @-webkit-keyframes slideFromLeft {
    0% {
    -webkit-transform: translateX(-100%);
    }

    100% {
    -webkit-transform: translateX(0);
    }
    }


    As seen, however, the second one doesn't behave as the first one, WHEN slide direction has changed.
    For instance:




    1. I slide to left the first one --> second slide loads with the correct animation

    2. Then, I slide to right the second one --> it is supposed the first slide to start appearance from the left side, while the second one to start disappearance to to the right side. Instead, as you may see, the second one start to disappear to the left and from the right side a white slide is shown. At some point, the first slide starts its appearance from the middle of the content.


    Please note, I deliberately delay the animations on the second example, just to see the undesired side effect mode clearly.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to "translate" this AngularJS slide left / right example to an AngularJS Material one.



      The latter link consists of the following code snippets:



      HTML code:



      <div ng-controller="ExampleController" ng-app="switchExample">
      <!--<select ng-model="slide" ng-options="item as item.name for item in slides">
      </select>-->
      <code>slide={{slide}}</code>
      <code>moveToLeft={{mtl}}</code>
      <md-button ng-click="prev()"><</md-button>
      <md-button ng-click="next()">></md-button>
      <div class="">
      <div class="ngSwitchItem" ng-if="slide.name == 'first'" ng-class="{'moveToLeft' : mtl}">
      <div class="firstPage page" md-swipe-left="selectPage(1)">
      first
      </div>
      </div>
      <div class="ngSwitchItem" ng-if="slide.name == 'second'" ng-class="{'moveToLeft' : mtl}">
      <div class="secondPage page" md-swipe-right="selectPage(0)" md-swipe-left="selectPage(2)">
      second
      </div>
      </div>
      <div class="ngSwitchItem" ng-if="slide.name == 'third'" ng-class="{'moveToLeft' : mtl}">
      <div class="thirdPage page" md-swipe-right="selectPage(1)" md-swipe-left="selectPage(3)">
      third
      </div>
      </div>
      <div class="ngSwitchItem" ng-if="slide.name == 'fourth'" ng-class="{'moveToLeft' : mtl}">
      <div class="fourthPage page" md-swipe-right="selectPage(2)">
      fourth
      </div>
      </div>
      </div>
      </div>


      JS code



      (function(angular) {
      'use strict';
      angular.module('switchExample', ['ngMaterial', 'ngAnimate'])
      .controller('ExampleController', ['$scope', function($scope) {

      $scope.slides = [
      { index: 0, name: 'first' },
      { index: 1, name: 'second' },
      { index: 2, name: 'third' },
      { index: 3, name: 'fourth' }
      ];
      $scope.selectPage = selectPage;
      /**
      * Initialize with the first page opened
      */
      $scope.slide = $scope.slides[0];

      $scope.prev = () => {
      if ($scope.slide.index > 0) {
      selectPage($scope.slide.index - 1);
      }
      }

      $scope.next = () => {
      if ($scope.slide.index < 3) {
      selectPage($scope.slide.index + 1);
      }
      }

      /**
      * @name selectPage
      * @desc The function that includes the page of the indexSelected
      * @param indexSelected the index of the page to be included
      */
      function selectPage(indexSelected) {
      if ($scope.slides[indexSelected].index > $scope.slide.index) {
      $scope.mtl = false;
      } else {
      $scope.mtl = true;
      }
      $scope.slide = $scope.slides[indexSelected];
      }
      }]);
      })(window.angular);


      CSS code



      body {
      overflow-x: hidden;
      }

      .ngSwitchItem {
      position: absolute;
      top: 50px;
      bottom: 0;
      right: 0;
      left: 0;

      animation-duration: 10.30s;
      animation-timing-function: ease-in-out;
      -webkit-animation-duration: 10.30s;
      -webkit-animation-timing-function: ease-in-out;

      }

      .page {
      position: inherit;
      top: 0;
      right: inherit;
      bottom: inherit;
      left: inherit;
      }

      .firstPage {
      background-color: blue;
      }

      .secondPage {
      background-color: red;
      }

      .thirdPage {
      background-color: green;
      }

      .fourthPage {
      background-color: yellow;
      }

      /* When the page enters, slide it from the right */
      .ngSwitchItem.ng-enter {
      animation-name: slideFromRight;
      -webkit-animation-name: slideFromRight;
      }
      /* When the page enters and moveToLeft is true, slide it from the left(out of the user view) to the right (left corner) */
      .ngSwitchItem.moveToLeft.ng-enter {
      animation-name: slideFromLeft;
      -webkit-animation-name: slideFromLeft;
      }
      /* When the page leaves, slide it to left(out of the user view) from the left corner,
      in other words slide it from the left(out of the view) to the left corner but in reverse order */
      .ngSwitchItem.ng-leave {
      animation-name: slideFromLeft;
      animation-direction: reverse;
      -webkit-animation-name: slideFromLeft;
      -webkit-animation-direction: reverse;
      }
      /* When the page leaves, slide it to the right(out of the user view) from the the left corner,
      in other words, slide it from the right but in reverse order */
      .ngSwitchItem.moveToLeft.ng-leave {
      animation-name: slideFromRight;
      animation-direction: reverse;
      -webkit-animation-name: slideFromRight;
      -webkit-animation-direction: reverse;
      }

      @keyframes slideFromRight {
      0% {
      transform: translateX(100%);
      }

      100% {
      transform: translateX(0);
      }
      }

      @keyframes slideFromLeft {
      0% {
      transform: translateX(-100%);
      }

      100% {
      transform: translateX(0);
      }
      }

      @-webkit-keyframes slideFromRight {
      0% {
      -webkit-transform: translateX(100%);
      }

      100% {
      -webkit-transform: translateX(0);
      }
      }

      @-webkit-keyframes slideFromLeft {
      0% {
      -webkit-transform: translateX(-100%);
      }

      100% {
      -webkit-transform: translateX(0);
      }
      }


      As seen, however, the second one doesn't behave as the first one, WHEN slide direction has changed.
      For instance:




      1. I slide to left the first one --> second slide loads with the correct animation

      2. Then, I slide to right the second one --> it is supposed the first slide to start appearance from the left side, while the second one to start disappearance to to the right side. Instead, as you may see, the second one start to disappear to the left and from the right side a white slide is shown. At some point, the first slide starts its appearance from the middle of the content.


      Please note, I deliberately delay the animations on the second example, just to see the undesired side effect mode clearly.










      share|improve this question















      I am trying to "translate" this AngularJS slide left / right example to an AngularJS Material one.



      The latter link consists of the following code snippets:



      HTML code:



      <div ng-controller="ExampleController" ng-app="switchExample">
      <!--<select ng-model="slide" ng-options="item as item.name for item in slides">
      </select>-->
      <code>slide={{slide}}</code>
      <code>moveToLeft={{mtl}}</code>
      <md-button ng-click="prev()"><</md-button>
      <md-button ng-click="next()">></md-button>
      <div class="">
      <div class="ngSwitchItem" ng-if="slide.name == 'first'" ng-class="{'moveToLeft' : mtl}">
      <div class="firstPage page" md-swipe-left="selectPage(1)">
      first
      </div>
      </div>
      <div class="ngSwitchItem" ng-if="slide.name == 'second'" ng-class="{'moveToLeft' : mtl}">
      <div class="secondPage page" md-swipe-right="selectPage(0)" md-swipe-left="selectPage(2)">
      second
      </div>
      </div>
      <div class="ngSwitchItem" ng-if="slide.name == 'third'" ng-class="{'moveToLeft' : mtl}">
      <div class="thirdPage page" md-swipe-right="selectPage(1)" md-swipe-left="selectPage(3)">
      third
      </div>
      </div>
      <div class="ngSwitchItem" ng-if="slide.name == 'fourth'" ng-class="{'moveToLeft' : mtl}">
      <div class="fourthPage page" md-swipe-right="selectPage(2)">
      fourth
      </div>
      </div>
      </div>
      </div>


      JS code



      (function(angular) {
      'use strict';
      angular.module('switchExample', ['ngMaterial', 'ngAnimate'])
      .controller('ExampleController', ['$scope', function($scope) {

      $scope.slides = [
      { index: 0, name: 'first' },
      { index: 1, name: 'second' },
      { index: 2, name: 'third' },
      { index: 3, name: 'fourth' }
      ];
      $scope.selectPage = selectPage;
      /**
      * Initialize with the first page opened
      */
      $scope.slide = $scope.slides[0];

      $scope.prev = () => {
      if ($scope.slide.index > 0) {
      selectPage($scope.slide.index - 1);
      }
      }

      $scope.next = () => {
      if ($scope.slide.index < 3) {
      selectPage($scope.slide.index + 1);
      }
      }

      /**
      * @name selectPage
      * @desc The function that includes the page of the indexSelected
      * @param indexSelected the index of the page to be included
      */
      function selectPage(indexSelected) {
      if ($scope.slides[indexSelected].index > $scope.slide.index) {
      $scope.mtl = false;
      } else {
      $scope.mtl = true;
      }
      $scope.slide = $scope.slides[indexSelected];
      }
      }]);
      })(window.angular);


      CSS code



      body {
      overflow-x: hidden;
      }

      .ngSwitchItem {
      position: absolute;
      top: 50px;
      bottom: 0;
      right: 0;
      left: 0;

      animation-duration: 10.30s;
      animation-timing-function: ease-in-out;
      -webkit-animation-duration: 10.30s;
      -webkit-animation-timing-function: ease-in-out;

      }

      .page {
      position: inherit;
      top: 0;
      right: inherit;
      bottom: inherit;
      left: inherit;
      }

      .firstPage {
      background-color: blue;
      }

      .secondPage {
      background-color: red;
      }

      .thirdPage {
      background-color: green;
      }

      .fourthPage {
      background-color: yellow;
      }

      /* When the page enters, slide it from the right */
      .ngSwitchItem.ng-enter {
      animation-name: slideFromRight;
      -webkit-animation-name: slideFromRight;
      }
      /* When the page enters and moveToLeft is true, slide it from the left(out of the user view) to the right (left corner) */
      .ngSwitchItem.moveToLeft.ng-enter {
      animation-name: slideFromLeft;
      -webkit-animation-name: slideFromLeft;
      }
      /* When the page leaves, slide it to left(out of the user view) from the left corner,
      in other words slide it from the left(out of the view) to the left corner but in reverse order */
      .ngSwitchItem.ng-leave {
      animation-name: slideFromLeft;
      animation-direction: reverse;
      -webkit-animation-name: slideFromLeft;
      -webkit-animation-direction: reverse;
      }
      /* When the page leaves, slide it to the right(out of the user view) from the the left corner,
      in other words, slide it from the right but in reverse order */
      .ngSwitchItem.moveToLeft.ng-leave {
      animation-name: slideFromRight;
      animation-direction: reverse;
      -webkit-animation-name: slideFromRight;
      -webkit-animation-direction: reverse;
      }

      @keyframes slideFromRight {
      0% {
      transform: translateX(100%);
      }

      100% {
      transform: translateX(0);
      }
      }

      @keyframes slideFromLeft {
      0% {
      transform: translateX(-100%);
      }

      100% {
      transform: translateX(0);
      }
      }

      @-webkit-keyframes slideFromRight {
      0% {
      -webkit-transform: translateX(100%);
      }

      100% {
      -webkit-transform: translateX(0);
      }
      }

      @-webkit-keyframes slideFromLeft {
      0% {
      -webkit-transform: translateX(-100%);
      }

      100% {
      -webkit-transform: translateX(0);
      }
      }


      As seen, however, the second one doesn't behave as the first one, WHEN slide direction has changed.
      For instance:




      1. I slide to left the first one --> second slide loads with the correct animation

      2. Then, I slide to right the second one --> it is supposed the first slide to start appearance from the left side, while the second one to start disappearance to to the right side. Instead, as you may see, the second one start to disappear to the left and from the right side a white slide is shown. At some point, the first slide starts its appearance from the middle of the content.


      Please note, I deliberately delay the animations on the second example, just to see the undesired side effect mode clearly.







      angularjs css3 angular-material css-animations






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 6:24

























      asked Nov 10 at 16:58









      Angel Todorov

      184213




      184213
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Actually, after a few more research hours, I found where the problem was buried - it seems, I have to move scope variable change for the next tick, to give time ng-class change to make its "magic".



          Long story short - adding the following is what made the thing work:



          $timeout(() => {
          $scope.slide = $scope.slides[indexSelected];
          }, 0)


          Here is the updated example and the code snippet below:



          JS code



          (function(angular) {
          'use strict';
          angular.module('switchExample', ['ngMaterial', 'ngAnimate'])
          .controller('ExampleController', ['$scope', '$timeout', function($scope, $timeout) {

          $scope.slides = [
          { index: 0, name: 'first' },
          { index: 1, name: 'second' },
          { index: 2, name: 'third' },
          { index: 3, name: 'fourth' }
          ];
          $scope.selectPage = selectPage;
          /**
          * Initialize with the first page opened
          */
          $scope.slide = $scope.slides[0];

          $scope.prev = () => {
          if ($scope.slide.index > 0) {
          selectPage($scope.slide.index - 1);
          }
          }

          $scope.next = () => {
          if ($scope.slide.index < 3) {
          selectPage($scope.slide.index + 1);
          }
          }

          /**
          * @name selectPage
          * @desc The function that includes the page of the indexSelected
          * @param indexSelected the index of the page to be included
          */
          function selectPage(indexSelected) {
          if ($scope.slides[indexSelected].index > $scope.slide.index) {
          $scope.mtl = false;
          } else {
          $scope.mtl = true;
          }
          // this will move a scope variable change to the next tick,
          // hence will give time $scope.mtl to be handled by ng-class
          $timeout(() => {
          $scope.slide = $scope.slides[indexSelected];
          }, 0)

          }
          }]);
          })(window.angular);





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241272%2fangularjs-material-slide-left-to-right-css3-animation%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Actually, after a few more research hours, I found where the problem was buried - it seems, I have to move scope variable change for the next tick, to give time ng-class change to make its "magic".



            Long story short - adding the following is what made the thing work:



            $timeout(() => {
            $scope.slide = $scope.slides[indexSelected];
            }, 0)


            Here is the updated example and the code snippet below:



            JS code



            (function(angular) {
            'use strict';
            angular.module('switchExample', ['ngMaterial', 'ngAnimate'])
            .controller('ExampleController', ['$scope', '$timeout', function($scope, $timeout) {

            $scope.slides = [
            { index: 0, name: 'first' },
            { index: 1, name: 'second' },
            { index: 2, name: 'third' },
            { index: 3, name: 'fourth' }
            ];
            $scope.selectPage = selectPage;
            /**
            * Initialize with the first page opened
            */
            $scope.slide = $scope.slides[0];

            $scope.prev = () => {
            if ($scope.slide.index > 0) {
            selectPage($scope.slide.index - 1);
            }
            }

            $scope.next = () => {
            if ($scope.slide.index < 3) {
            selectPage($scope.slide.index + 1);
            }
            }

            /**
            * @name selectPage
            * @desc The function that includes the page of the indexSelected
            * @param indexSelected the index of the page to be included
            */
            function selectPage(indexSelected) {
            if ($scope.slides[indexSelected].index > $scope.slide.index) {
            $scope.mtl = false;
            } else {
            $scope.mtl = true;
            }
            // this will move a scope variable change to the next tick,
            // hence will give time $scope.mtl to be handled by ng-class
            $timeout(() => {
            $scope.slide = $scope.slides[indexSelected];
            }, 0)

            }
            }]);
            })(window.angular);





            share|improve this answer

























              up vote
              0
              down vote













              Actually, after a few more research hours, I found where the problem was buried - it seems, I have to move scope variable change for the next tick, to give time ng-class change to make its "magic".



              Long story short - adding the following is what made the thing work:



              $timeout(() => {
              $scope.slide = $scope.slides[indexSelected];
              }, 0)


              Here is the updated example and the code snippet below:



              JS code



              (function(angular) {
              'use strict';
              angular.module('switchExample', ['ngMaterial', 'ngAnimate'])
              .controller('ExampleController', ['$scope', '$timeout', function($scope, $timeout) {

              $scope.slides = [
              { index: 0, name: 'first' },
              { index: 1, name: 'second' },
              { index: 2, name: 'third' },
              { index: 3, name: 'fourth' }
              ];
              $scope.selectPage = selectPage;
              /**
              * Initialize with the first page opened
              */
              $scope.slide = $scope.slides[0];

              $scope.prev = () => {
              if ($scope.slide.index > 0) {
              selectPage($scope.slide.index - 1);
              }
              }

              $scope.next = () => {
              if ($scope.slide.index < 3) {
              selectPage($scope.slide.index + 1);
              }
              }

              /**
              * @name selectPage
              * @desc The function that includes the page of the indexSelected
              * @param indexSelected the index of the page to be included
              */
              function selectPage(indexSelected) {
              if ($scope.slides[indexSelected].index > $scope.slide.index) {
              $scope.mtl = false;
              } else {
              $scope.mtl = true;
              }
              // this will move a scope variable change to the next tick,
              // hence will give time $scope.mtl to be handled by ng-class
              $timeout(() => {
              $scope.slide = $scope.slides[indexSelected];
              }, 0)

              }
              }]);
              })(window.angular);





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Actually, after a few more research hours, I found where the problem was buried - it seems, I have to move scope variable change for the next tick, to give time ng-class change to make its "magic".



                Long story short - adding the following is what made the thing work:



                $timeout(() => {
                $scope.slide = $scope.slides[indexSelected];
                }, 0)


                Here is the updated example and the code snippet below:



                JS code



                (function(angular) {
                'use strict';
                angular.module('switchExample', ['ngMaterial', 'ngAnimate'])
                .controller('ExampleController', ['$scope', '$timeout', function($scope, $timeout) {

                $scope.slides = [
                { index: 0, name: 'first' },
                { index: 1, name: 'second' },
                { index: 2, name: 'third' },
                { index: 3, name: 'fourth' }
                ];
                $scope.selectPage = selectPage;
                /**
                * Initialize with the first page opened
                */
                $scope.slide = $scope.slides[0];

                $scope.prev = () => {
                if ($scope.slide.index > 0) {
                selectPage($scope.slide.index - 1);
                }
                }

                $scope.next = () => {
                if ($scope.slide.index < 3) {
                selectPage($scope.slide.index + 1);
                }
                }

                /**
                * @name selectPage
                * @desc The function that includes the page of the indexSelected
                * @param indexSelected the index of the page to be included
                */
                function selectPage(indexSelected) {
                if ($scope.slides[indexSelected].index > $scope.slide.index) {
                $scope.mtl = false;
                } else {
                $scope.mtl = true;
                }
                // this will move a scope variable change to the next tick,
                // hence will give time $scope.mtl to be handled by ng-class
                $timeout(() => {
                $scope.slide = $scope.slides[indexSelected];
                }, 0)

                }
                }]);
                })(window.angular);





                share|improve this answer












                Actually, after a few more research hours, I found where the problem was buried - it seems, I have to move scope variable change for the next tick, to give time ng-class change to make its "magic".



                Long story short - adding the following is what made the thing work:



                $timeout(() => {
                $scope.slide = $scope.slides[indexSelected];
                }, 0)


                Here is the updated example and the code snippet below:



                JS code



                (function(angular) {
                'use strict';
                angular.module('switchExample', ['ngMaterial', 'ngAnimate'])
                .controller('ExampleController', ['$scope', '$timeout', function($scope, $timeout) {

                $scope.slides = [
                { index: 0, name: 'first' },
                { index: 1, name: 'second' },
                { index: 2, name: 'third' },
                { index: 3, name: 'fourth' }
                ];
                $scope.selectPage = selectPage;
                /**
                * Initialize with the first page opened
                */
                $scope.slide = $scope.slides[0];

                $scope.prev = () => {
                if ($scope.slide.index > 0) {
                selectPage($scope.slide.index - 1);
                }
                }

                $scope.next = () => {
                if ($scope.slide.index < 3) {
                selectPage($scope.slide.index + 1);
                }
                }

                /**
                * @name selectPage
                * @desc The function that includes the page of the indexSelected
                * @param indexSelected the index of the page to be included
                */
                function selectPage(indexSelected) {
                if ($scope.slides[indexSelected].index > $scope.slide.index) {
                $scope.mtl = false;
                } else {
                $scope.mtl = true;
                }
                // this will move a scope variable change to the next tick,
                // hence will give time $scope.mtl to be handled by ng-class
                $timeout(() => {
                $scope.slide = $scope.slides[indexSelected];
                }, 0)

                }
                }]);
                })(window.angular);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 7:07









                Angel Todorov

                184213




                184213






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241272%2fangularjs-material-slide-left-to-right-css3-animation%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Error while running script in elastic search , gateway timeout

                    Adding quotations to stringified JSON object values