JQuery implements the return to top function. jquery implements the return to top function.

Source: Internet
Author: User

JQuery implements the return to top function. jquery implements the return to top function.

The code is very simple. There is not much nonsense here. Let's look at the code.

HTML:

<! -- Go to Top --> <div id = "Fixed"> <a id = "goTop" class = "fl" title = "Go Top" href = "javascript :; "> go to the top </a> </div> <! -- Go to Top end -->

CSS:

. Fl {display: block; float: left; width: 50px; height: 50px; text-align: center; background-color: # eaeaea; background-image: url (.. /images/toTop.png );}. fl: hover {background-color: # f48942; background-image: url (.. /images/toTop.png);} # Fixed {position: fixed; _ position: absolute; z-index: 100; bottom: 70px; left: 50%; margin-left: 530px; _ bottom: auto; _ top: expression(document.documentElement.scrollTop+document.doc umentElement. clientHeight-this.offsetHeight-70); width: 50px; text-indent:-40000px; background: # fff}/* top end */

Js:

/* Top setting function */$ (function () {$ (window ). bind ('scroll', {fixedOffsetBottom: parseint('{fixed'}.css ('bottom ')}, function (e) {var scrollTop = $ (window ). scrollTop (); var referFooter =$ ('# footer'); scrollTop> 100? $ ('# GoTop'). show (): $ ('# goTop'). hide (); if (! /Msie 6/I. test (navigator. userAgent) {if ($ (window ). height ()-(referFooter. offset (). top-$ (window ). scrollTop ()> e. data. fixedOffsetBottom) {{('{fixed'}.css ('bottom ', $ (window ). height ()-(referFooter. offset (). top-$ (window ). scrollTop ()} else {response ('{fixed'}.css ('bottom ', e. data. fixedOffsetBottom) }}); $ ('# goTop '). click (function () {$ ('body, html '). stop (). animate ({'scrolltop ': 0, 'duration': 100, 'easing': 'wait-in'}) ;});/* Top-Down Function end */

Articles you may be interested in:
  • JQuery animated volume page returns top animation effects (compatible with Chrome)
  • Jquery-based return to the top effect (compatible with IE6)
  • Returns the jquery implementation code at the top of the Sina Weibo record.
  • How does js + JQuery return to the top?
  • Code for returning to the top of smart hiding and sliding effects implemented by jQuery
  • JQuery's return to the top function is suitable for browsers that do not support js.

Related Article

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.