Code for redirecting javascript code to the position of a specified Element

Source: Internet
Author: User

This article will introduce you to the program for redirecting to the specified element. This is a good transfer program. If you need to know about it, you will not be able to access it.

The Code is as follows: Copy code
/**
* Jump to the position of the specified Element
* Usage
* Scroller (el, duration)
* El: Target anchor ID
* Duration: the duration, in milliseconds. The smaller the value, the faster the duration.
*/
Var flutil = {
Intval: function (v ){
V = parseInt (v );
Return isNaN (v )? 0: v;
},
GetPos: function (e) {// obtain Element Information
Var l = 0;
Var t = 0;
Var w = this. intval (e. style. width );
Var h = this. intval (e. style. height );
Var wb = e. offsetWidth;
Var hb = e. offsetHeight;
While (e. offsetParent ){
L + = e. offsetLeft + (e. currentStyle? This. intval (e. currentStyle. borderLeftWidth): 0 );
T + = e. offsetTop + (e. currentStyle? This. intval (e. currentStyle. borderTopWidth): 0 );
E = e. offsetParent;
}
L + = e. offsetLeft + (e. currentStyle? This. intval (e. currentStyle. borderLeftWidth): 0 );
T + = e. offsetTop + (e. currentStyle? This. intval (e. currentStyle. borderTopWidth): 0 );
Return {
X: l,
Y: t,
W: w,
H: h,
Wb: wb,
Hb: hb
};
},
GetScroll: function () {// get the scroll bar Information
Var t, l, w, h;
If (document.doc umentElement & document.doc umentElement. scrollTop ){
T = document.doc umentElement. scrollTop;
L = document.doc umentElement. scrollLeft;
W = document.doc umentElement. scrollWidth;
H = document.doc umentElement. scrollHeight;
} Else if (document. body ){
T = document. body. scrollTop;
L = document. body. scrollLeft;
W = document. body. scrollWidth;
H = document. body. scrollHeight;
}
Return {
T: t,
L: l,
W: w,
H: h
};
},
Scroroller: Smooth jump between functions (el, duration) {// Anchor
If (typeof el! = 'Object '){
El = document. getElementById (el );
}
If (! El) return;
Var z = this;
Z. el = el;
Z. p = this. getPos (el );
Z. s = this. getScroll ();
Z. clear = function (){
Window. clearInterval (z. timer );
Z. timer = null
};
Z. t = (new Date). getTime ();
Z. step = function (){
Var t = (new Date). getTime ();
Var p = (t-z. t)/duration;
If (t> = duration + z. t ){
Z. clear ();
Window. setTimeout (function (){
Z. scroll (z. p. y, z. p. x)
}, 13 );
} Else {
St = (-Math. cos (p * Math. PI)/2) + 0.5) * (z. p. y-z. s. t) + z. s. t;
Sl = (-Math. cos (p * Math. PI)/2) + 0.5) * (z. p. x-z. s. l) + z. s. l;
Z. scroll (st, sl );
}
};
Z. scroll = function (t, l ){
Window. scrollTo (l, t)
};
Z. timer = window. setInterval (function (){
Z. step ();
}, 13 );
}
}

Related Article

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.