Frequently used small Demo: Use Js/jquery to return to the top of the page function

Source: Internet
Author: User

HTML code:

<div class= "main" > Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab amet debitis, dolore eveniet illo maiores nam neque nesciunt perspiciatis praesentium quaerat qui, quidem rem sequi sim    Ilique sunt ullam Voluptate voluptates!</div>//is responsible for accommodating various buttons such as "Back to top of page", "Sweep QR Code" and so on <div class= "Backcontainer" > <a href= "#" id= "Backtop" ></a></div>


CSS code:

*{margin:0; padding:0;} A{color: #000; text-decoration:none;}. main{width:100%; height:1500px;}. backcontainer{position:fixed; right:40px; bottom:40px;} #backTop {display:block; width:46px; height:46px; Background:url (' images/go-top.png ') no-repeat 0-100px;} #backTop: hover{background-position-y:-150px;}


"Back to Top" button and mouse move-in effect:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/8A/2B/wKiom1gpd6fyuIxpAAAD0PxqpD8101.png "title=" Qq20161114163610.png "alt=" wkiom1gpd6fyuixpaaad0pxqpd8101.png "/> 650" this.width=650; "src=" http://s5.51cto.com /wyfs02/m00/8a/2b/wkiom1gpd7iwyttzaaadfyagcnu525.png "title=" Qq20161114163621.png "alt=" Wkiom1gpd7iwyttzaaadfyagcnu525.png "/>


JS Code:

$ ('. Backcontainer '). Hide (); $ (window). Scroll (function () {///when the offset of the window relative to the top of the scrollbar is greater than 150px, the Jump button is displayed, otherwise the if (window) is not displayed.    ScrollTop () > () {$ ('. Backcontainer '). FadeIn (' slow ');    }else{$ ('. Backcontainer '). FadeOut (' slow '); }});//When you click the Jump button, $ (' #backTop '). Click (function () {$ (' html '). Animate ({scrolltop:0},1000);})


Scroll ([[DATA],FN]):

The scroll event occurs when the user scrolls the specified element.

The Scroll event applies to all scrollable elements and window objects (browser windows).

$ (window). Scroll (function () {/* ... do something ... */});


Animate (PARAMS,[SPEED],[EASING],[FN])

The function used to create the custom animation. The key to this function is to specify the animation form and the result style Property object. Each property in this object represents a style property that can vary (such as "height", "top", or "opacity"). Note: All specified properties must be in camel form, such as marginleft instead of Margin-left.

Apply three types of effects in one animation at the same time

$ ("#go"). Click (function () {

$ ("#block"). Animate ({

width: "90%",

Height: "100%",

fontSize: "10em",

borderwidth:10

}, 1000);

});


ScrollTop ([Val])

Gets the offset of the matching element at the top of the scroll bar, which is valid for both visible and hidden elements.







This article is from the "Dapengtalk" blog, make sure to keep this source http://dapengtalk.blog.51cto.com/11549574/1872718

Frequently used small Demo: Use Js/jquery to return to the top of the page function

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.