Returns the top 3 Chinese method (solves the effect that the mobile side uses zepto without sliding)

Source: Internet
Author: User

Click Back to top, three ways

1, this method jquery use normal, zepto use no animation

// Zepto No animation $ ("body"). Animate ({scrolltop:0}, $)//Zepto use $ ("body"). ScrollTop ( 0);

2, this method jquery use normal, zepto use no animation

Window.scrollto (0,0);

3, Zepto use can have animation

functiongotop (acceleration, time) {acceleration= Acceleration | | 0.1; time= Time | | 16;varX1 = 0;varY1 = 0;varx2 = 0;vary2 = 0;varx3 = 0;varY3 = 0;if(document.documentelement) {x1= Document.documentElement.scrollLeft | | 0; Y1= Document.documentElement.scrollTop | | 0;}if(document.body) {x2= Document.body.scrollLeft | | 0; Y2= Document.body.scrollTop | | 0;}varx3 = WINDOW.SCROLLX | | 0;varY3 = window.scrolly | | 0;//horizontal distance from scroll bar to top of pagevarx =Math.max (x1, Math.max (x2, x3));//vertical distance from scroll bar to top of pagevary =Math.max (y1, Math.max (y2, y3));//scrolling distance = current distance/speed, because the distance is smaller, the speed is greater than 1 of the number, so the rolling distance will be more and more smallvarSpeed = 1 +Acceleration;window.scrollto (Math.floor (x/speed), Math.floor (Y/Speed ));//if the distance is nonzero, continue calling the iteration functionif(X > 0 | | y > 0) {varInvokefunction = "Gotop (" + Acceleration + "," + Time + ")"; Window.settimeout (invokefunction, Time);}} $(". Fix_go_top"). On ("click",function() {    //$ ("body"). ScrollTop (0);    //Window.scrollto (0,0);gotop ();});

Returns the top 3 Chinese method (solves the effect that the mobile side uses zepto without sliding)

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.