可能是一个微不足道的问题,但我找不到解决方案。以下代码:
$.extend(Module.prototype, {
initialize : function() {
...
$('.afx-list a').on('click', $.proxy(function() {
this.onClickEventHandler(/* argumentIwantTohave - clicked element */);
return false;
}, this));
...
},
...
onClickEventHandler : function(/* argumentIwantTohave */) {
var currentScrollTop = 0,
destinationScrollTop = 0,
offsetScrollTop = 0;
currentScrollTop = $(document).scrollTop();
destinationScrollTop = $('a[name=' + $(this).attr('href').split('#')[1] + ']').offset().top;
// Resolvin the problem with missing 1px when scrolling to destination
if(currentScrollTop < destinationScrollTop) {
offsetScrollTop = 1;
} else {
offsetScrollTop = -1;
}
$('body').animate({
scrollTop: destinationScrollTop + offsetScrollTop
}, 1000);
},
});
现在,在 '$('.afx-list a').on('click', $.proxy(function()' 函数中,我需要两个变量 - Module.prototype 范围来调用 'onClickEventHandle' 和单击的元素范围将其作为参数传递。
我可以同时有两个上下文吗?对于: 1. Module.prototype 2. 点击元素
我试过这样的东西
$('.afx-list a').on('click', $.proxy(function() {
this.onClickEventHandler(/* argumentIwantTohave - clicked element */);
return false;
}, { clicked : /* dont know what is the refference */, module : this}));
但我不知道应该为“clicked”属性放置什么参考。