Backbone.Marionette Fade Transition仅适用于特定地区?

dkl*_*mer 9 marionette

我知道我可以通过使用以下内容覆盖所有区域以添加淡入淡出过渡.

Marionette.Region.prototype.open = function(view){
  this.$el.hide();
  this.$el.html(view.el);
  this.$el.fadeIn()
}
Run Code Online (Sandbox Code Playgroud)

有没有办法只覆盖特定的区域或视图?我的布局中有某些区域我希望能够淡入,而其他区域应该立即渲染.

谢谢,

DK

Der*_*ley 16

您可以定义自Region定义任何Backbone对象的方式,并将此代码添加到该区域类型.


MyRegion = Backbone.Marionette.Region.extend({

  el: "#some-element",

  open: function(view){
    this.$el.hide();
    this.$el.html(view.el);
    this.$el.fadeIn();
  }

});

MyApp.addRegions({
  myRegion: MyRegion
});
Run Code Online (Sandbox Code Playgroud)

请注意,我el在区域定义中包含了该内容.如果要在多个区域中重复使用它,则必须创建一个基本区域,并根据需要为每个区域进行扩展.


FadeInRegion = Backbone.Marionette.Region.extend({

  open: function(view){
    this.$el.hide();
    this.$el.html(view.el);
    this.$el.fadeIn();
  }

});

MyApp.addRegions({
  myRegion: FadeInRegion.extend({el: "#some-element"}),
  anotherRegion: FadeInRegion.extend({el: "#another-element"})
});
Run Code Online (Sandbox Code Playgroud)