Backbone.Marionette淡入淡出仅针对特定区域? [英] Backbone.Marionette Fade Transition for only specific regions?
问题描述
我知道我可以使用以下内容覆盖所有区域以添加淡入淡出过渡.
I know I can override all regions to add a fade transition by using the following.
Marionette.Region.prototype.open = function(view){
this.$el.hide();
this.$el.html(view.el);
this.$el.fadeIn()
}
是否有仅覆盖特定区域或视图的方法?我希望布局中的某些区域能够淡入,而其他区域应立即呈现.
Is there a way to only override specific regions or views? I have certain regions in my layout that I would like to be able to fade in while other regions should be rendered instantly.
谢谢
dk
推荐答案
您可以定义自定义Region
的方式来定义任何Backbone对象,并将此代码添加到该区域类型.
You can define a custom Region
the way you can define any Backbone object, and add this code to that region type.
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
});
请注意,我在区域定义中包括了el
.如果要在多个区域中重复使用它,则必须创建一个基础区域,并从该基础区域扩展到所需的每个基础区域.
Note that I included the el
in the region definition. If you want to re-use this across multiple regions, you'll have to create a base region and extend from that for each one that you need.
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"})
});
这篇关于Backbone.Marionette淡入淡出仅针对特定区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!