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 ); } } |