1

ビューポートよりもはるかに大きく、ドラッグ可能な「workArea」というキャンバスがあります。私はそれが関連しているとは思わないが、そこに投げ出す. 以下の init 関数を使用して、ノックアウトで要素を動的に作成しています。連続する各要素を、最後の要素から右と下に 25 ピクセルずつ作成する必要があります (技術的には選択された要素ですが、最後に作成された要素が自動的に選択されます)。locy 変数は 25 を介して設定され、予想どおりに増加しているように見えますが、locx 変数は毎回指数関数的に大きくなります。私は愚かな何かを見逃しているに違いない。

Javascript:

ko.bindingHandlers.Item = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
    var $element = $(element);
    var locx;
    var locy;
    var $pos = $('.itemView.focused').position();
    var $work = $('#workArea');
    if ($('.itemView.focused').length > 0) {
        locx = $pos.left;
        locy = $pos.top;
        console.log('focused element "' + $('.itemView.focused').attr('name') + '" is at ' + locx + ',' + locy)
    } else {
        locx = $work.width() / 2;
        locy = $work.height() / 2;
        console.log('No focused elements, creating at ' + locx + ',' + locy)
    }
    $element.draggable({ ...draggable options here...});
    locx += 25;
    locy += 25;
    $element.css('left', locx.toString() + 'px').css('top', locy.toString() + 'px');
    console.log('Created new element at ' + locx + ',' + locy)
    }
};

そして、これがコンソールログで、UI に表示されている場所と一致しています。

No focused elements, creating at 2000,1000
Created new element at 2025,1025
focused element "SERVER01" is at 2025,1025
Created new element at 2050,1050
focused element "SERVER02" is at 2298,1050
Created new element at 2323,1075
focused element "SERVER03" is at 2819,1075
Created new element at 2844,1100
focused element "APP01" is at 3588,1100
Created new element at 3613,1125
4

1 に答える 1

0

問題が見つかりました...私が忘れていたCSSクラスに不正な「float:left」スタイルが適用されていました。

今は完璧に機能しています。

私は「あまりにもローカライズされている」ことに投票しますが、これはかなり奇妙な動作のように思えるので、誰かを助けることができるでしょうか? 誰かが閉鎖に投票しても、私は気分を害しません。

于 2013-06-25T23:14:30.200 に答える