1

clone()jQueryのヘルプが必要です。

つまり、これは次のとおりです。タッチデバイスで動作するある種のドラッグ&ドロップ&ソートを行っています。要素を複製すると、イベントがなくなることを除いて、すべてが良好です(ドラッグが機能しなくなります)。

コードは次のようになります (簡略化されています)。

$('li', layers).each(function(){
    this.addEventListener('touchend', function(e){
        var cloned = $(this).clone( true, true ); // no events are cloned at all!
        cloned.insertBefore( this.helper ); 

    }); //ontouchend

    this.addEventListener('touchmove', function(e){
        // do some stuff with this.helper
    });
});

私は何を間違っていますか?

ありがとう!

4

1 に答える 1

1

DOM 要素は 1 つのもの (および自動的に複製されない) であるため、次のような関数を使用するinsertBeforeと、要素をコピーする代わりに移動できます。この「トリック」を利用すると、すべてがバインドされたまったく同じ要素であるため、イベントが複製されないという問題も発生しません。

したがって、たとえば次のことができます。

this.addEventListener('touchend', function(e){
    this.insertBefore( this.helper ); 
}); //ontouchend
于 2011-08-17T11:23:45.333 に答える