需要setOnLoadCallback()替代方案

Joy*_*rex 1 jquery google-ajax-api

我正在开发一个内部网站,无法对Google的API进行外部调用以使用他们的setOnLoadCallback()函数,而且似乎无法找到任何可以与我本地调用的JQuery一起使用的纯JQuery替代品.作为参考,这是我正在尝试实现的代码,但原始开发人员使用Google API编写代码:

<script type="text/javascript">

  google.load("jquery", "1.3.2");

  google.load("jqueryui", "1.7.2");



  google.setOnLoadCallback(function() { 

    var timeout = null;

    var initialMargin = parseInt($("#siteMenuBar").css("margin-top"));



    $("#siteMenuBar").hover(

        function() {

            if (timeout) {

                clearTimeout(timeout);

                timeout = null;

            }

            $(this).animate({ marginTop: 0 }, 'fast');

        },

        function() {

            var menuBar = $(this);

            timeout = setTimeout(function() {

                timeout = null;

                menuBar.animate({ marginTop: initialMargin }, 'slow');

            }, 1000);

        }

    );

  });

</script>
Run Code Online (Sandbox Code Playgroud)

任何建议/想法都表示赞赏.

Jon*_*ron 6

我想你需要的只是替换

google.setOnLoadCallback(function() { 
Run Code Online (Sandbox Code Playgroud)

$(document).ready(function() {
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助 !