On the PC we can easily use scrolltop () to achieve the flow of the upward scrolling back to the top of the animation, and then use the Web mobile but no eggs, there will be scrolling is not smooth, lag, failure and so on.
This is because the mobile side of the scroll event trigger is not frequent, it is possible to detect a situation with <=0
To this end, the number of mobile judgment is better,
Here is the specific implementation code, compatible with the PC:
Return Top animation//gotop (+);//500ms roll back to top function gotop (times) {if (!!! Times) {$ (window). scrolltop (0); Return } var sh=$ (' body '). scrolltop ();//Mobile Total distance var inter=13.333;//ms, each move interval var forcount=math.ceil (times/inter);//number of moves Var Stepl=math.ceil (Sh/forcount);//move step var timeid=null; function ani () {!! Timeid&&cleartimeout (Timeid); Timeid=null; Console.log ($ (' body '). scrolltop ()); if ($ (' body '). ScrollTop () <=0| | forcount<=0) {//Mobile judgment number is better, because the mobile side of the scroll event trigger is not frequent, it is possible to detect the <=0 of the case $ (' body '). scrolltop (0); Return } forcount--; SH-=STEPL; $ (' body '). scrolltop (SH); Timeid=settimeout (function () {ANI ();},inter); } ani ();}
About the solution that the Web mobile end returns to the top