/** * Jump to the location of the specified element * Use method * Scroller (el, duration) * El: Target anchor Point ID * Duration: Duration, in milliseconds, smaller, faster */ var flutil = { Intval:function (v) { v = parseint (v); return isNaN (v)? 0:v; }, Getpos:function (e) {//Get 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 scroll bar information var T, L, W, H; if (document.documentelement && document.documentElement.scrollTop) { t = Document.documentElement.scrollTop; L = document.documentElement.scrollLeft; W = document.documentElement.scrollWidth; h = document.documentElement.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 }; }, Scroller:function (el, duration) {//Anchor point (anchor) smooth jump between 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); } } |