我正在研究适应性电子学习框架,我试图将notify-popup(div)垂直对齐。为此,我通过js设置上边距,这需要notify-popup的高度,所以我使用$('.notify-popup').height(true)
得到它的高度。第一次加载时它返回高度" x"但如果我再次调用该函数而不重新加载页面,则返回新的高度,并添加16px" x + 16"。要包含我使用outerHeight(true)
的所有填充和边距,但它也不起作用。在预渲染页面期间,jquery的height()方法是否排除或遗漏了高度计算中的某些内容?在初始呈现页面后,它在调用resetNotifySize函数时返回正确的高度。
setupEventListener: function() {
this.listenTo(Adapt, 'device:resize', this.resetNotifySize);
}
showNotifyOnPageLoaded: function() {
this.resizeNotify();
}
resizeNotify: function() {
var notifyHeight = this.$('.notify-popup').outerHeight(true);
this.$('.notify-popup').css({
'margin-top': (-(notifyHeight / 2))
});
}
resetNotifySize: function() {
console.log('resizeNotify called through resetNotifySize');
this.resizeNotify();
}