Jquery returns to the top source code for sharing-jquery returns to the top source code
// JavaScript Document (function ($) {var goToTopTime; $. fn. goToTop = function (options) {var opts = $. extend ({}, $. fn. goToTop. def, options); var $ window =$ (window); $ body = (window. opera )? (Document. compatMode = "CSS1Compat "? $ ('Html '): $ ('body'): $ ('html, body'); // opera fix $ (this ). hide (); var $ this = $ (this); clearTimeout (goToTopTime); goToTopTime = setTimeout (function () {var controlLeft; if ($ window. width ()> opts. pageHeightJg * 2 + opts. pageWidth) {controlLeft = ($ window. width ()-opts. pageWidth)/2 + opts. pageWidth + opts. pageWidthJg;} else {controlLeft = $ window. width ()-opts. pageWidthJg-$ this. width ();} var cs Sfixedsupport = $. browser. msie & parseFloat ($. browser. version) <7; // determines whether ie6 var controlTop = $ window. height ()-$ this. height ()-opts. pageHeightJg; controlTop = cssfixedsupport? $ Window. scrollTop () + controlTop: controlTop; var shouldvisible = ($ window. scrollTop ()> = opts. startline )? True: false; if (shouldvisible) {$ this. stop (). show (opts. showBtntime);} else {$ this. stop (). hide (opts. showBtntime);} Then this.css ({position: cssfixedsupport? 'Absolute ': 'fixed', top: controlTop, left: controlLeft}) ;}, 500); $ (this ). click (function (event) {$ body. stop (). animate ({scrollTop: entries (opts.tar getObg ). offset (). top}, opts. duration); $ (this ). blur (); event. preventDefault (); event. stopPropagation () ;}) ;}; $. fn. goToTop. def = {pageWidth: 950, // page width pageWidthJg: 10, // The interval between the button and the page is: 50, // The interval between the button and the page bottom is startline: 20, // The scrollTop of the scroll bar that appears to return to the top is 200 away from duration: 100, // The speed time for returning to the top showBtntime:, // display \ hide the speed time for returning to the top button targetObg: "body" // target location };}) (jQuery); $ (function () {$ ('<a href = "#" class = "go-top"> </ a> '). appendTo ("body ");});
Note that the 18th-line variable cssfixedsupport supports position: fixed bug in ie6.
Var cssfixedsupport = $. browser. msie & parseFloat ($. browser. version) <7; // determines whether ie6var controlTop = $ window. height ()-$ this. height ()-opts. pageHeightJg; controlTop = cssfixedsupport? $ Window. scrollTop () + controlTop: controlTop;
For example, in IE6, use absolute for layout. When you scroll the mouse, you must use $ window. scrollTop () to obtain the vertical height of the scroll bar to the top to correct the controlTop parameter.
Trigger the mouse to click the event to return to the top!