1

これをうまく説明できればと思います。

else if ステートメント内に mousedown および mouseup 関数があります (これにより、ユーザーはページ内のオブジェクトをドラッグでき、特定のモードに従って実行されるポインターおよびマウス イベントに関連付けられます)。

コード:

}else if(typeof mode !== 'undefined' && mode === 'move'){

        toolId =        'toolMove';
        this.deselectAllElems($svgContentRef);  
        fdtObj.dragMode = true;

        $('#formWrap').draggable( "option", "disabled", false ).addClass('dragCursor');
        $svgContentRef.css({ cursor: 'url(images/cursor_drag.gif),auto' });

        $('#formWrap').bind('mousedown',function() {
            $svgContentRef.css({ cursor: 'url(images/cursor_dragging.gif),auto' });
        });
        $('#formWrap').unbind('mousedown',event);

        $('#formWrap').bind('mouseup',function() {
            $svgContentRef.css({ cursor: 'url(images/cursor_drag.gif),auto' });
        });
        $('#formWrap').unbind('mouseup',event);
    }else{

        $svgContentRef.css('cursor','default');

    }

問題は、別のモード (現在のモード以外) をクリックすると、マウスダウン イベントがまだ発生しているようです。アンバインドが正しく処理されていないと思われます。

どんな助けでも大歓迎です。

4

3 に答える 3

1

これが完全な機能です。クライアントが別のモードをクリックするとカーソルオプションがリセットされるという点で、すべてが機能しています。ただし、ドラッグモードでは、ドラッグカーソルのmousedownは、mouseupと同様に最初は機能しますが、その後、mouseupオプションのままになります。つまり、mousedownが2回目に起動されない場合、コードは次のようになります。

    this.switchDesignMode = function(mode){

    fdtObj.dragMode = false;

    $('#formWrap').draggable({ disabled: true });
    $('#formWrap').removeClass('dragCursor').css('cursor','');
    //$('#formWrap').unbind('mousedown');
    //$('#formWrap').unbind('mouseup');

    designMode =                mode;                                                                           

    var $sideRef =              this.getCurrentSideRef(),                                                       
        $svgContentRef =        this.getSvgContentRef($sideRef),                                                
        $panelTools =           $('#panelTools'),                                                               
        toolId =                'toolPointer';                                                                  

    if(typeof mode !== 'undefined' && mode === 'text'){

        toolId =                'toolText';
        this.deselectAllElems($svgContentRef);                                                                  
        $svgContentRef.css('cursor','text');                                                                    

    }else if(typeof mode !== 'undefined' && mode === 'move'){

        toolId =                'toolMove';
        this.deselectAllElems($svgContentRef);                                                                  
        fdtObj.dragMode = true;

        $('#formWrap').draggable( "option", "disabled", false ).addClass('dragCursor');
        $svgContentRef.css({ cursor: 'url(images/cursor_drag.gif),auto' });

        function handler1(eventObject){
            $svgContentRef.css({ cursor: 'url(images/cursor_dragging.gif),auto' });
            $(this).unbind('mousedown', handler1);
        }
        $('#formWrap').bind('mousedown', handler1);

        function handler2(eventObject) {
            $svgContentRef.css({ cursor: 'url(images/cursor_drag.gif),auto' });
            $(this).unbind('mouseup', handler2);
        }
        $('#formWrap').bind('mouseup', handler2);

    }else{

        $svgContentRef.css('cursor','default');                                                                 

    }

    $panelTools.find('a').removeClass('active');                                                                
    $panelTools.find('a#' + toolId).addClass('active');                                                         

};

(関数の上部にバインド解除オプションを設定しようとしましたが、これは機能しませんでした。

これが明確であることを願っています。L

于 2012-05-17T08:49:17.690 に答える
1

変数イベントはどこから来るのですか? ハンドラから渡されたパラメータですか?

その場合、unbind() に渡す必要があるのは、bind() または live() で渡した同じ関数への参照です。

したがって、次のようなことができます。

$('#formWrap').bind('mousedown',function() {
        ....
        $(this).unbind('mousedown', this);
    });

どこ$(this) refers to $('#formWrap')this refers to the function in scope

アップデート

する代わりに$('#formWrap').bind('mousedown',function() {...});

function handler(eventObject){
   .....
   $(this).unbind('mousedown', handler);
}

$('#formWrap').bind('mousedown', handler);
于 2012-05-16T13:49:27.747 に答える
0

これを試して:

   $('#formWrap').bind('mousedown',function() {
        $svgContentRef.css({ cursor: 'url(images/cursor_dragging.gif),auto' });
        $(this).unbind('mousedown');
    });

onとメソッドを使用することもできoffます:

   $('#formWrap').on('mousedown',function() {
        $svgContentRef.css({ cursor: 'url(images/cursor_dragging.gif),auto' });
        $(this).off('mousedown');
    });
于 2012-05-16T13:48:54.527 に答える