【发布时间】:2014-02-08 00:33:26
【问题描述】:
上下文
包含人力资源信息的用户页面。
我在用户图片下有一个大小不固定的菜单。
我在图片加载时更新菜单margin-top:
_setMenuMarginTop: function () {
var that = this;
$('#picture > img').load(function () {
that.$el.css('margin-top', $(this).height() + 'px');
});
}
当当前用户发生变化时,我更新页面(用户信息,用户图片img)然后我调用_setMenuMarginTop方法,因为图片大小不一样:
initialize: function () {
this.listenTo(app.curUser, 'sync', this._updateView);
},
...
_updateView: function () {
this._setMenuMarginTop();
// Other stuffs...
},
但是这次 jQuery 没有触发 .load 方法。
问题
- 知道为什么吗?
- 它只工作一次吗?
- 解决方法?
更多信息
img 更新到另一个视图:
initialize: function () {
this.listenTo(app.curUser, 'sync', this._updateCurUserInfo);
}
...
_updateCurUserInfo: function () {
this.$el.find('#picture').html( this.templatePicture({ 'url' : getPictureUrl(app.curUser.get('picture')) }) );
// Other stuffs...
}
【问题讨论】:
标签: javascript jquery html css image