How to jump to the specified location of another page, jump to the specified location of the page

Source: Internet
Author: User

How to jump to the specified location of another page, jump to the specified location of the page

How to jump to a specified position on another page:
On the same page, it is very easy to click a place to jump to the specified location, that is, the anchor, for example:

 

<A href = "# thediv"> ant tribe </a>

 

The code above allows you to jump to the element whose id attribute value is thediv when you click element.
The above describes the situation on the same page. If it is a different page, you can also locate it like this, as long as you add a link to the front:

 

<A href = "mytest. aspx # thediv"> ant tribe </a>

 

Click the link to find the element whose id attribute value is thediv on the mytest. aspx page.
However, the positions above are all after clicking, and it may not be nice enough to arrive at the specified position in an instant. If you can smoothly scroll to that position, it would be better. Here is a brief introduction, the Code is as follows:

 

function getParam() {   var params=location.search.substr(1)  var ArrParam=params.split('#');   if(ArrParam.length>1)   {   return ArrParam[1];  } } $(function(){   var mao=$("#"+getParam());  if(mao.length>0)   {    var pos=mao.offset().top;     var poshigh=mao.height();     $("html,body").animate({scrollTop:pos-poshigh-30},3000);   } }); 

 

The above code is very simple and I will not introduce it here.
Related reading:
1. For details about location. search, see the search attribute section of the Location object.
2. For details about the substr () function, refer to substr () method 1 of the String object in javascript.
3. For details about the split () function, see section 1 of the split () method of the String object in JavaScript.
4. For details about offset, see the offset () method section of jQuery.
5. For details about the height () function, see the height () method section of jQuery.
6. For details about the animate () function, refer to the animate () method section of jQuery.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 9331.

For more information, see: http://www.softwhy.com/jquery/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.