需要setOnLoadCallback()替代方案

时间:2011-03-23 21:38:10

标签: 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>

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

1 个答案:

答案 0 :(得分:6)

我认为您需要的只是替换

google.setOnLoadCallback(function() { 

$(document).ready(function() {

我希望这有帮助!

相关问题