0

In the events hash, i want to use resize event, but they do not work neither. However, click event works well. why resize does not work?

var SubheaderView = Backbone.View.extend({

    id: 'gallery',
    tagName: 'div',

    events: {
        'click #minor': 'getPadding',
        'resize #minor': 'getPadding' //not work
    },

    initialize: function() {
        this.render();
    },

    render: function() {
        this.$el.append(subheaderTemplate);
    },

    getPadding: function() {
        var pad_top = Math.floor($('#minor').height() * 0.4);
        var pad_left = Math.floor($('#minor').width() * 0.07);
        var pad = pad_top + 'px 0px 0px ' + pad_left + 'px';

        $('#cover h1').css({'padding': pad});
    }
});
Will
  • 633
  • 11
  • 26

2 Answers2

2

It does not related to Backbone at all. According to MDN, only window has a resize event.

Engineer
  • 47,849
  • 12
  • 88
  • 91
0

You can do something like this: Add this code to backbone.js file you are using

Backbone.View.prototype.eventAggregator = _.extend({}, Backbone.Events);
  $(window).resize(function () {
  Backbone.View.prototype.eventAggregator.trigger('window:resize');
});

Then bind the event aggregator to any view to want to use the resize event

this.eventAggregator.bind('window:resize',this.resize)

where this.resize is the function to be called for the resize event

neel shah
  • 2,231
  • 15
  • 19