Implementation code for a jquery-based jump from one page to the specified location on another page

Source: Internet
Author: User

For example, to jump to the mao.aspx page div id= "s" position then only with <a href= "mao.aspx#s" > can be implemented to jump to the specified location
Now in order to increase the user experience to jump to the page after the smooth move to that location how to do it is actually very simple to pass over there a parameter to jump to which div on the line
First on a page to get the parameters of the Universal JS

Copy CodeThe code is as follows:
Get the parameter pname equals the desired parameter name according to the argument name
function GetParam (pname) {
var params = location.search.substr (1); Get the parameters flat and remove?
var arrparam = params.split (' & ');
if (arrparam.length = = 1) {
Case with only one parameter
return params.split (' = ') [1];
}
else {
Conditions for multiple parameter parameters
for (var i = 0; i < arrparam.length; i++) {
if (arrparam[i].split (' = ') [0] = = pname) {
return arrparam[i].split (' = ') [1];
}
}
}
}


The code is simple enough to get the value of the desired parameter from the current URL.

Copy CodeThe code is as follows:
$ (function () {
var Mao = $ ("#" + GetParam ("M")); Get anchor Points
if (Mao.length > 0) {//Determine if object exists
var pos = Mao.offset (). Top;
var Poshigh = Mao.height ();
$ ("Html,body"). Animate ({scrolltop:pos-poshigh-30}, 3000);
}
});


Above is the smooth move to the desired position pos-poshigh-30 This can be adjusted I think it's a good thing to lose to 30.

Very simple effect not on the code example of their own writing to play ~

Implementation code for a jquery-based jump from one page to the specified location on another page

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.