0

些細な質問かもしれませんが、解決策が見つかりません。次のコード:

$.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()'' 関数内で、'onClickEventHandle' とクリックされた要素を呼び出すための Module.prototype スコープの両方の変数が必要ですscope を引数として渡します。

一度に 2 つのコンテキストを持つことはできますか? 対象: 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}));

しかし、「クリックされた」プロパティにどの参照を配置する必要があるかわかりません。

4

0 に答える 0