0
我使用Backbone渲染一個方形瓷磚元素,我在其中設置高度,然後動態設置寬度以匹配高度。但是,當試圖獲取元素高度時,我得到0
返回。動態設置元素的高度和寬度
這裏是我的代碼:
var app = app || {};
app.ClassModelView = Backbone.View.extend({
className: 'tile',
template: _.template('<%= name %>'),
render: function() {
var dim = 'calc(' + parseInt(100/app.global.rows) + '% - ' + app.global.margin * (app.global.rows + 1) + 'px)'; //e.g. "30% - 20px"
this.$el.append(this.template(this.model.attributes)).css({
margin: app.global.margin + 'px',
height: dim,
}).css({
width: this.$el.height() + 'px',
});
return this;
}
})
我將如何設置$el
的高度寬度?我不確定是否我的語法錯誤,或者是使用Backbone的方式導致我的問題。
您可以嘗試使用'.outerHeight(真)'代替。如果它不起作用,請考慮上傳代碼到http://www.jsfiddle.net向我們展示您的問題 – Itay