滚动到页面加载的特定区域并执行Ajax查询(Scroll to specific area on page load AND perform Ajax Query)

美好的一天人们。 当我链接到页面上的特定部分后,我需要弄清楚如何使用Ajax执行操作。 我已经知道如何到达另一个页面上指定的DOM元素,但是我希望进一步去使用ajax执行一些操作,一旦它将访问者带到那一点。

例如。

<nav> <ul><li><a href="about.php#team"></a></li></ul> </nav>

将带我到这个about.php页面的“团队”div

<div> <div><a name="team"></a></div> </div>

但后来我想自动运行一些Ajax,这通常会在用户点击“团队”div中的某个对象时执行。 所以如果用户通过上面的链接进入本节,则会直接看到内容。 那有意义吗?

Good day folks. I need to figure out how to perform an action using Ajax once I have linked to a specific section on a page. I already know how to get to the designated DOM element on the other page, but I would like to go further as to perform some action using ajax once it has taken the visitor to that point.

eg.

<nav> <ul><li><a href="about.php#team"></a></li></ul> </nav>

Will take me to this about.php page to the "team" div

<div> <div><a name="team"></a></div> </div>

But then I would like to run some Ajax automatically that would usually be executed when the user clicks on some object in the "team" div. So should the user get to this section by way of the link up above, it will take them straight to the content. Does that make sense?

最满意答案

您可以使用jQuery的scrollTo()滚动到页面上的区域,然后使用complete函数在滚动完成后调用您的Ajax。 详细描述在这里

$('body').scrollTo('#target', function() { // Do your AJAX Thaaang });

You can use jQuery's scrollTo() to scroll to the area on the page, then use the complete function to call you ajax after the scroll has finished. Detailed Description here

$('body').scrollTo('#target', function() { // Do your AJAX Thaaang });滚动到页面加载的特定区域并执行Ajax查询(Scroll to specific area on page load AND perform Ajax Query)

美好的一天人们。 当我链接到页面上的特定部分后,我需要弄清楚如何使用Ajax执行操作。 我已经知道如何到达另一个页面上指定的DOM元素,但是我希望进一步去使用ajax执行一些操作,一旦它将访问者带到那一点。

例如。

<nav> <ul><li><a href="about.php#team"></a></li></ul> </nav>

将带我到这个about.php页面的“团队”div

<div> <div><a name="team"></a></div> </div>

但后来我想自动运行一些Ajax,这通常会在用户点击“团队”div中的某个对象时执行。 所以如果用户通过上面的链接进入本节,则会直接看到内容。 那有意义吗?

Good day folks. I need to figure out how to perform an action using Ajax once I have linked to a specific section on a page. I already know how to get to the designated DOM element on the other page, but I would like to go further as to perform some action using ajax once it has taken the visitor to that point.

eg.

<nav> <ul><li><a href="about.php#team"></a></li></ul> </nav>

Will take me to this about.php page to the "team" div

<div> <div><a name="team"></a></div> </div>

But then I would like to run some Ajax automatically that would usually be executed when the user clicks on some object in the "team" div. So should the user get to this section by way of the link up above, it will take them straight to the content. Does that make sense?

最满意答案

您可以使用jQuery的scrollTo()滚动到页面上的区域,然后使用complete函数在滚动完成后调用您的Ajax。 详细描述在这里

$('body').scrollTo('#target', function() { // Do your AJAX Thaaang });

You can use jQuery's scrollTo() to scroll to the area on the page, then use the complete function to call you ajax after the scroll has finished. Detailed Description here

$('body').scrollTo('#target', function() { // Do your AJAX Thaaang });