如何在滑块内容中调用ajax之后获取目标元素的位置?

时间:2011-11-11 17:47:42

标签: javascript jquery jquery-ui-slider

我试图在滑块内容中调用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中的完整代码。

以下是测试site

我知道如何才能得到正确的数字吗?

0 个答案:

没有答案
相关问题