JQuery returns the top, jquery returns the top
It's a simple thing to record:
Mainly monitors the $ (window). scroll () event.
Jquery. top. js
/*** JQuery returns the top ** @ author: xuzengqiang * @ since: 14:45:59 **/; (function ($) {jQuery. fn. backTop = function (options) {var defaultOptions = {hideIndex: 200, // The hidden position hideTimer: 1000, // The time used to hide the return button. backIndex: 0, // The position to move. By default, the backTimer at the top is returned: 500 // The time required to return the top}; var settings = jQuery. extend (defaultOptions, options | |{}), current =$ (this); $ (window ). scroll (function () {var timer = settings. hideTimer; if ($ (this ). scrollTop ()> = settings. hideIndex) {current. fadeIn (timer);} else {current. fadeOut (timer) ;}}); return this. each (function () {current. click (function () {$ ("body, html "). stop (false, true ). animate ({scrollTop: settings. backIndex}, settings. backTimer) ;}) ;};}( jQuery );
Call example:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">