|
428 | 428 | * called `ng-animate-ref`.
|
429 | 429 | *
|
430 | 430 | * Let's say for example we have two views that are managed by `ng-view` and we want to show
|
431 |
| - * that there is a relationship between two components situated in different views. By using the |
| 431 | + * that there is a relationship between two components situated in within these views. By using the |
432 | 432 | * `ng-animate-ref` attribute we can identify that the two components are paired together and we
|
433 | 433 | * can then attach an animation, which is triggered when the view changes.
|
434 | 434 | *
|
| 435 | + * Say for example we have the following template code: |
| 436 | + * |
435 | 437 | * ```html
|
436 | 438 | * <!-- index.html -->
|
437 | 439 | * <div ng-view class="view-animation">
|
438 | 440 | * </div>
|
439 | 441 | *
|
440 | 442 | * <!-- home.html -->
|
441 | 443 | * <a href="#/banner-page">
|
442 |
| - * <img src="./banner.jpg" ng-animate-ref="banner"> |
| 444 | + * <img src="./banner.jpg" class="banner" ng-animate-ref="banner"> |
443 | 445 | * </a>
|
444 | 446 | *
|
445 | 447 | * <!-- banner-page.html -->
|
446 |
| - * <img src="./banner.jpg" ng-animate-ref="banner"> |
| 448 | + * <img src="./banner.jpg" class="banner" ng-animate-ref="banner"> |
447 | 449 | * ```
|
448 | 450 | *
|
449 | 451 | * Now, when the view changes (once the link is clicked), ngAnimate will examine the
|
450 | 452 | * HTML contents to see if there is a match reference between any components in the view
|
451 |
| - * that is leaving and the view that is entering. It will then attempt to trigger a CSS |
452 |
| - * animation on the `.view-animation-anchor` CSS class (notice how `.view-animation` is |
453 |
| - * a shared CSS class on the ng-view element? This means that view-animation will apply to |
454 |
| - * both the enter and leave animations). |
| 453 | + * that is leaving and the view that is entering. It will scan both the view which is being |
| 454 | + * removed (leave) and inserted (enter) to see if there are any paired DOM elements that |
| 455 | + * contain a matching ref value. |
455 | 456 | *
|
456 |
| - * The two images match since they share the same ref value. ngAnimate will now apply a |
457 |
| - * suffixed version of each of the shared CSS classes with `-anchor`. Therefore we will |
458 |
| - * have a shared class of `view-animation-anchor` which we can use to setup our transition animation. |
| 457 | + * The two images match since they share the same ref value. ngAnimate will now create a |
| 458 | + * transport element (which is a clone of the first image element) and it will then attempt |
| 459 | + * to animate to the position of the second image element in the next view. For the animation to |
| 460 | + * work a special CSS class called `ng-anchor` will be added to the transported element. |
459 | 461 | *
|
460 |
| - * We can now attach a transition onto the `.view-animation-anchor` CSS class and then |
| 462 | + * We can now attach a transition onto the `.banner.ng-anchor` CSS class and then |
461 | 463 | * ngAnimate will handle the entire transition for us as well as the addition and removal of
|
462 | 464 | * any changes of CSS classes between the elements:
|
463 | 465 | *
|
464 | 466 | * ```css
|
465 |
| - * .view-animation-anchor { |
| 467 | + * .banner.ng-anchor { |
466 | 468 | * /* this animation will last for 1 second since there are
|
467 | 469 | * two phases to the animation (an `in` and an `out` phase) */
|
468 | 470 | * transition:0.5s linear all;
|
469 | 471 | * }
|
470 | 472 | * ```
|
471 | 473 | *
|
472 |
| - * There are two stages for an anchor animation: `out` and `in`. The `out` stage happens first and that |
473 |
| - * is when the element is animated away from its origin. Once that animation is over then the `in` stage |
474 |
| - * occurs which animates the element to its destination. The reason why there are two animations is to |
475 |
| - * give enough time for the enter animation on the new element to be ready. |
| 474 | + * We also **must** include animations for the views that are being entered and removed |
| 475 | + * (otherwise anchoring wouldn't be possible since the new view would be inserted right away). |
| 476 | + * |
| 477 | + * ```css |
| 478 | + * .view-animation.ng-enter, .view-animation.ng-leave { |
| 479 | + * transition:0.5s linear all; |
| 480 | + * position:fixed; |
| 481 | + * left:0; |
| 482 | + * top:0; |
| 483 | + * width:100%; |
| 484 | + * } |
| 485 | + * .view-animation.ng-enter { |
| 486 | + * transform:translateX(100%); |
| 487 | + * } |
| 488 | + * .view-animation.ng-leave, |
| 489 | + * .view-animation.ng-enter.ng-enter-active { |
| 490 | + * transform:translateX(0%); |
| 491 | + * } |
| 492 | + * .view-animation.ng-leave.ng-leave-active { |
| 493 | + * transform:translateX(-100%); |
| 494 | + * } |
| 495 | + * ``` |
| 496 | + * |
| 497 | + * Now we can jump back to the anchor animation. When the animation happens, there are two stages that occur: |
| 498 | + * an `out` and an `in` stage. The `out` stage happens first and that is when the element is animated away |
| 499 | + * from its origin. Once that animation is over then the `in` stage occurs which animates the |
| 500 | + * element to its destination. The reason why there are two animations is to give enough time |
| 501 | + * for the enter animation on the new element to be ready. |
476 | 502 | *
|
477 | 503 | * The example above sets up a transition for both the in and out phases, but we can also target the out or
|
478 | 504 | * in phases directly via `ng-anchor-out` and `ng-anchor-in`.
|
479 | 505 | *
|
480 | 506 | * ```css
|
481 |
| - * .view-animation-anchor.ng-anchor-out { |
| 507 | + * .banner.ng-anchor-out { |
482 | 508 | * transition: 0.5s linear all;
|
483 | 509 | *
|
484 | 510 | * /* the scale will be applied during the out animation,
|
485 | 511 | * but will be animated away when the in animation runs */
|
486 | 512 | * transform: scale(1.2);
|
487 | 513 | * }
|
488 | 514 | *
|
489 |
| - * .view-animation-anchor.ng-anchor-in { |
| 515 | + * .banner.ng-anchor-in { |
490 | 516 | * transition: 1s linear all;
|
491 | 517 | * }
|
492 | 518 | * ```
|
|
580 | 606 | width:100%;
|
581 | 607 | min-height:500px;
|
582 | 608 | }
|
583 |
| - .view.ng-enter { |
| 609 | + .view.ng-enter, .view.ng-leave, |
| 610 | + .record.ng-anchor { |
584 | 611 | transition:0.5s linear all;
|
| 612 | + } |
| 613 | + .view.ng-enter { |
585 | 614 | transform:translateX(100%);
|
586 | 615 | }
|
587 |
| - .view.ng-enter.ng-enter-active { |
| 616 | + .view.ng-enter.ng-enter-active, .view.ng-leave { |
588 | 617 | transform:translateX(0%);
|
589 | 618 | }
|
590 |
| - .view.ng-leave { |
591 |
| - transition:0.5s linear all; |
592 |
| - } |
593 | 619 | .view.ng-leave.ng-leave-active {
|
594 | 620 | transform:translateX(-100%);
|
595 | 621 | }
|
596 |
| - .view-anchor { |
597 |
| - transition:0.5s linear all; |
| 622 | + .record.ng-anchor-out { |
| 623 | + background:red; |
598 | 624 | }
|
599 | 625 | </file>
|
600 | 626 | </example>
|
|
0 commit comments