Backbone.Marionette Fade Transition for only specific regions?

后端 未结 2 1095
暗喜
暗喜 2021-02-03 12:04

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.$         


        
2条回答
  •  攒了一身酷
    2021-02-03 13:09

    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
    });
    

    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"})
    });
    

提交回复
热议问题