Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果异步加载JS文件,则SmoothDivScroll jQuery插件不工作_Javascript_Jquery_Plugins_Asynchronous_Smooth Scrolling - Fatal编程技术网

Javascript 如果异步加载JS文件,则SmoothDivScroll jQuery插件不工作

Javascript 如果异步加载JS文件,则SmoothDivScroll jQuery插件不工作,javascript,jquery,plugins,asynchronous,smooth-scrolling,Javascript,Jquery,Plugins,Asynchronous,Smooth Scrolling,我使用的是SmoothDivScroll,在我尝试异步加载所有JS文件之前,它工作得非常好。我使用Ryan Grove的异步加载模式,但可以肯定的是,我还使用的load/complete模式进行了测试,得到了相同的结果。我测试了一份来自的快速演示部分,刚刚添加了Modernizer。没有Modernizr,这很好,但当我在头部添加Modernizr及其加载/完成模式,并注释掉end body标记之前的所有JS时,它不再工作了。当您将鼠标悬停在右箭头上时,什么也不会发生,而将鼠标悬停在左箭头上会导

我使用的是SmoothDivScroll,在我尝试异步加载所有JS文件之前,它工作得非常好。我使用Ryan Grove的异步加载模式,但可以肯定的是,我还使用的load/complete模式进行了测试,得到了相同的结果。我测试了一份来自的快速演示部分,刚刚添加了Modernizer。没有Modernizr,这很好,但当我在头部添加Modernizr及其加载/完成模式,并注释掉end body标记之前的所有JS时,它不再工作了。当您将鼠标悬停在右箭头上时,什么也不会发生,而将鼠标悬停在左箭头上会导致图像闪烁。这两种方式都应该是一样的。Moderizer块应等同于它下面的所有块:

    <script type="text/javascript"> 
        Modernizr.load([ {
            load: [
                '//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js',
                '/js/jquery-ui-1.8.23.custom.min.js',
                '/js/jquery.mousewheel.min.js',
                '/js/jquery.kinetic.js',
                '/js/jquery.smoothdivscroll-1.3-min.js'
            ],
            complete: 
                function () {     
                  $(document).ready(function () {
                        $("#makeMeScrollable").smoothDivScroll({
                            mousewheelScrolling: "allDirections",
                            manualContinuousScrolling: true,
                            autoScrollingMode: "onStart"
                        });
                    });
                }
            }
        ]); 
    </script>        

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
    <script src="/js/jquery-ui-1.8.23.custom.min.js" type="text/javascript"></script>
    <script src="/js/jquery.mousewheel.min.js" type="text/javascript"></script>
    <script src="/js/jquery.kinetic.js" type="text/javascript"></script>
    <script src="/js/jquery.smoothdivscroll-1.3-min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#makeMeScrollable").smoothDivScroll({
                mousewheelScrolling: "allDirections",
                manualContinuousScrolling: true,
                autoScrollingMode: "onStart"
            });
        });
    </script>

现代化负载([{
负载:[
“//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js”,
“/js/jquery-ui-1.8.23.custom.min.js”,
“/js/jquery.mouseweel.min.js”,
“/js/jquery.kinetic.js”,
“/js/jquery.smoothdivscroll-1.3-min.js”
],
完成:
函数(){
$(文档).ready(函数(){
$(“#makeMeScrollable”).smoothDivScroll({
鼠标滚轮滚动:“所有方向”,
manualContinuousScrolling:正确,
自动克隆模式:“onStart”
});
});
}
}
]); 
$(文档).ready(函数(){
$(“#makeMeScrollable”).smoothDivScroll({
鼠标滚轮滚动:“所有方向”,
manualContinuousScrolling:正确,
自动克隆模式:“onStart”
});
});

我修改了如下代码段

      complete: 
            function () {     
                  $("#makeMeScrollable").smoothDivScroll({
                        mousewheelScrolling: "allDirections",
                        manualContinuousScrolling: true,
                        autoScrollingMode: "onStart"
                  });
            }
        }

modernizer
完成时将就绪事件处理程序附加到文档将无法工作,因为该文档已由浏览器加载和解析。

感谢Ashwini完成了此操作,尽管我不明白具体原因。Complete在load中加载的内容完成时启动。在DOM准备就绪之前,加载的内容可能会完成,也可能不会完成。我不确定如何知道在每个浏览器中的每种情况下,complete是否会在DOM就绪之前完成。