超时后滚动窗口

发布于 2024-08-15 16:31:50 字数 348 浏览 1 评论 0原文

我希望能够使用 jQuery 的scrollTo 插件在加载 Google 方向时将窗口动画向下滚动到 div。有人可以帮我将 setTimeout 行转换为 jQuery 并使用scrollTo 来设置滚动动画吗?这是不滚动的 JavaScript:

      GEvent.addListener(gdir, 'load',  onGDirectionsLoad)

        function onGDirectionsLoad(){   
            setTimeout('eval(\'window.location = "#directions"\;\')', 500); 

        }

I would like to be able to use jQuery's scrollTo plugin to animate the window scroll down to a div when Google directions are loaded. Could someone please help me convert the setTimeout line to jQuery and use scrollTo to animate the scroll? Here is the javascript that doesn't scroll:

      GEvent.addListener(gdir, 'load',  onGDirectionsLoad)

        function onGDirectionsLoad(){   
            setTimeout('eval(\'window.location = "#directions"\;\')', 500); 

        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菩提树下叶撕阳。 2024-08-22 16:31:50

使用匿名函数而不是 eval()

function onGDirectionsLoad() {
  setTimeout(function(){
    $.scrollTo("#directions", 1000);
  }, 500);
}

* 使用 Ariel Flesler 的 $.scrollTo() jQuery 插件。

Use an anonymous function rather than eval():

function onGDirectionsLoad() {
  setTimeout(function(){
    $.scrollTo("#directions", 1000);
  }, 500);
}

* Uses Ariel Flesler's $.scrollTo() jQuery Plugin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文