如何:在页面加载后单击jQuery Scrollto Action,而不是单击? [英] Howto: Jquery Scrollto Action after Pageload instead Click?

查看:95
本文介绍了如何:在页面加载后单击jQuery Scrollto Action,而不是单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想出这个需要更好的解释:

Figured this needed a better explanation:

我在导航中有一些链接:

I have a navigation with some links:

<a id="home" href="/">Home</a>
<a id="screenshots" class="scroll_to_screenshots" href="#">Screenshots</a>
<a id="ask" class="scroll_to_container" href="/ask">Support</a>

我有一个包含以下内容的js文件:

And I have a js file with the following:

$(document).ready(function() {
$(".scroll_to_screenshots").click(function() {$.scrollTo($("#screenshots").position().top+10, 300)});
$(".scroll_to_container").click(function() {$.scrollTo($("#container").position().top-10, 300)});
});

现在,对于屏幕截图,它可以正常工作:它向下滚动到屏幕截图ID.但是第二个需要先加载页面,然后滚动.显然,这是行不通的(它会向下滚动一下,然后开始页面加载.我可以将该操作更改为-load page首先,-scroll down吗?

Now for the screenshots it works fine: it scrolls down to the screenshots id. However the second one needs to load a page first, then scroll. Obviously that does not work (it scrolls down briefly and then the page loading kicks in. Can I change that action to -load page first, -scroll down?

然后很明显,我遇到另一个问题,当我在.../上时,第一个链接不再起作用.

And then obviously I have another problem, when I am on .../ask the first link doesn't work anymore.

推荐答案

而不是使用它:

$(document).ready(function(){
   // Your stuff here
});

尝试使用此:

$(window).load(function(){
   // Your stuff here
});

这将使脚本等到页面上的所有元素都被加载后才滚动.

This will make the script wait until all elements on the page are loaded in before it scrolls.

这篇关于如何:在页面加载后单击jQuery Scrollto Action,而不是单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆