Javascript scroller的图像预加载存在chrome和webkit问题

Javascript scroller的图像预加载存在chrome和webkit问题,javascript,jquery,google-chrome,preload,Javascript,Jquery,Google Chrome,Preload,我目前正在修改smoothDivScrolljquery插件,我发现它在Chrome和Safari中存在问题 在谷歌搜索和StackOverflow搜索之后,我可以将这归因于Chrome和Safari中计算图像尺寸的方式存在问题 问题是,在chrome和Safari中,图像在滚动条中显示时还不可见,在这些浏览器中无法计算滚动条的总宽度,并生成一系列空白 我得出的结论是,需要对图像进行预加载,以便能够计算其中的尺寸 以下是违规代码: // Add up the total width of all

我目前正在修改
smoothDivScroll
jquery插件,我发现它在Chrome和Safari中存在问题

在谷歌搜索和StackOverflow搜索之后,我可以将这归因于Chrome和Safari中计算图像尺寸的方式存在问题

问题是,在chrome和Safari中,图像在滚动条中显示时还不可见,在这些浏览器中无法计算滚动条的总宽度,并生成一系列空白

我得出的结论是,需要对图像进行预加载,以便能够计算其中的尺寸

以下是违规代码:

// Add up the total width of all the items inside the scrollable area
el.data("scrollableArea").children(o.countOnlyClass).each(function () {
    // Check to see if the current element in the loop is the one where the scrolling should start
    if ($(this).is('img')) {

        if ((o.startAtElementId.length !== 0) && (($(this).attr("id")) === o.startAtElementId)) {
            el.data("startingPosition", tempScrollableAreaWidth);
            foundStartAtElement = true;
        }
        var ow = $(this).outerWidth(true);

        if (ow == 0) ow = 1 * $(this).find("img").attr("width");

        el.data("allImages").each(function () {
            var ths = $(this);
            var kx = eh / 1 * ths.attr("height");
            ths.attr({
                width: kx / ths.attr("width"),
                height: eh
            })
        })
        //tempScrollableAreaWidth +" "+ $(this).outerWidth(true) + " "
        tempScrollableAreaWidth = tempScrollableAreaWidth + ow;

    }
});
在这个脚本运行之前,我已经尝试过从外部预加载图像,但是chrome和safari只会偶尔运行它们,预加载的图像似乎永远不会成功


我想知道是否有人可以告诉我如何在此脚本中预加载这些图像,以便通过最后处理的计算可以访问图像尺寸,即
tempScrollableAreaWidth

在该函数中使用图像加载函数刷新或创建滚动条