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/