JQuery returns the top, jquery returns the top

Source: Internet
Author: User

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"> 




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.