1

スライダー コンテンツで ajax を呼び出した後、対象の要素の位置を取得しようとしていますが、ここでコードを動作させるのに問題があります。これが私のajax(ロード)コードです:

// Load the article into container_article.
container_article.load(path, function(){

    // Get the width of the loaded article first.
    var width_article = container_article.width();

    // Add the article width into the existing content container width.
    scroll_content.width(scroll_content.width() + width_article + 2);

    // Get the position of current requested article.
    var block_request = $('.block-'+ request).css({background:'red'});
    var position_request = $('.block-'+ request).position();
    alert(position_request.left);
    //alert(block_request.offset().left);

    // Get the percentage of the handle.
    var scroll_maximum = scroll_content.width() - scroll_frame.width();
    var percentage = Math.round((position_request.left/scroll_maximum) * 100);

    // Send the percentage to scrollbar.
    scrollbar.slider("value",percentage);

    // Attach other functions.
    exit_article (container_article);

});

結果、

// 311 (block 1)
// 915 (block 2)
// 1120 (block 3)
// 1420 (block 4)
// 1375 (block 5)

しかし、彼らはそうあるべきです、

// 307.44 (block 1)
// 922.32 (block 2)
// 1511.58 (block 3)
// 2126.46 (block 4)
// 2562 (block 5)

jsfiddleのコード全体を次に示します。

テストサイトはこちら。

数字を正しく取得する方法はありますか?

4

0 に答える 0