Ember.enrutador js: Cómo animar transiciones de estado


¿Alguien ha encontrado una buena manera de animar las transiciones de estado?

El router elimina inmediatamente la vista del DOM. El problema con eso es que no puedo posponerlo hasta el final de la animación. Nota: Estoy usando v1.0.0-pre.4.

Author: Stephen Sprinkle, 2013-01-25

6 answers

Billy's Billing acaba de lanzar un módulo Ember que soporta transiciones animadas.

 10
Author: camdub,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-09 23:01:08

Voy a ampliar la respuesta de Lesyk. Si necesita aplicarlo a varias vistas de una manera seca, puede crear una clase de personalización como esta:

App.CrossfadeView = {
  didInsertElement: function(){
    //called on creation
    this.$().hide().fadeIn(400);
  },
  willDestroyElement: function(){
    //called on destruction
    this.$().slideDown(250);
  }
};

Y luego en su código lo aplica en sus diversas clases de vista. Como Ember depende de jQuery, puede usar casi cualquier animación jQuery.

App.IndexView = Ember.View.extend(App.CrossfadeView);
App.PostView = Ember.View.extend(App.CrossfadeView);
 7
Author: Bojan Markovic,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-27 13:22:09

Se encontró con este mismo requisito en mi aplicación. Probé Ember Animated Outlet , pero no me dio la granularidad que necesitaba (animaciones específicas de elementos).

La solución que funcionó para mí fue la siguiente {

Cambiar Enlace a para que sea una acción

{{#linkTo "todos"}}<button>Todos</button>{{/linkTo}}

Se convierte...

<a href="#/todos" {{action "goToTodos"}}><button>Todos</button></a>

Crear método para goToTodos en el controlador actual

App.IndexController = Ember.Controller.extend({
    goToTodos: function(){

        // Get Current 'this' (for lack of a better solution, as it's late)
            var holdThis = this;

        // Do Element Specific Animation Here
            $('#something').hide(500, function(){

                // Transition to New Template
                    holdThis.transitionToRoute('todos');

            });

    }
});

Finalmente use Para animar elementos en la plantilla Todos, use didInsertElement en la vista

App.TodosView = Ember.View.extend({
    didInsertElement: function(){

        // Hide Everything
            this.$().hide();

        // Do Element Specific Animations Here
            $('#something_else').fadeIn(500);

    }
});

Hasta ahora, esta es la solución más elegante que he encontrado para animaciones específicas de elementos en transición. Si hay algo mejor, me encantaría escuchar!

 6
Author: Stephen Sprinkle,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-10 08:01:06

Sé que esto es bastante antiguo, pero la mejor solución para esta animación específica del contexto actual es probablemente ember liquid fire.

Te permite hacer cosas como esta en un archivo de transición:

export default function(){
  this.transition(
    this.fromRoute('people.index'),
    this.toRoute('people.detail'),
    this.use('toLeft'),
    this.reverse('toRight')
  );
};
 6
Author: max,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-25 03:50:29

He encontrado otra solución desplegable que implementa animaciones en vistas: ember-animate

Ejemplo:

App.ExampleView = Ember.View.extend({

    willAnimateIn : function () {
        this.$().css("opacity", 0);
    },

    animateIn : function (done) {
        this.$().fadeTo(500, 1, done);
    },

    animateOut : function (done) {
        this.$().fadeTo(500, 0, done);
    }
}

Demo: sitio web personal del autor

 4
Author: Dmitry Pashkevich,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-06 09:35:46
App.SomeView = Ember.View.extend({
  didInsertElement: function(){
   //called on creation
   this.$().hide().fadeIn(400);
  },
  willDestroyElement: function(){
   //called on destruction
   this.$().slideDown(250)
  }
});
 1
Author: lesyk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-05 16:12:29