【发布时间】:2019-06-09 14:27:41
【问题描述】:
当我滚动 div 时,基本上没有任何反应。 slideIt 方法在对象启动时被触发一次,就是这样。它不听滚动事件!为什么会发生这种情况?
function fixed_column_or_row(container_name){
this.container_div=$(container_name);
this.scrollable_div=this.container_div.find(".simplebar-content-wrapper");
this.fixed_row=this.container_div.find(".fixed-row")
this.fixed_column=this.container_div.find(".fixed-column")
//the issue in this line
this.scrollable_div.scroll(this.slideIt())
}
fixed_column_or_row.prototype.slideIt=function(){
var scrollTop = this.scrollable_div.scrollTop(),
scrollLeft = this.scrollable_div.scrollLeft();
console.log("scrollTop")
this.fixed_row.css({
"margin-left": -scrollLeft
});
this.fixed_column.css({
"margin-top": -scrollTop
});
}
【问题讨论】:
-
表达式
this.scrollable_div.scroll(this.slideIt())调用该函数。您需要传递对函数的绑定引用:this.scrollable_div.scroll(this.slideIt.bind(this))。 -
@Pointy 成功了。请把它作为答案,以便我批准。
标签: javascript jquery javascript-objects