Webtouch (WebApp) page, anti-Apple mobile Safari browser, online swipe, bottom navigation disappears, swipe to bottom and appear again. Swipe down and the bottom navigation appears.
Encounter problems
1, I started with Swipeup and Swipedown to do, found that because there are scroll bar, will not trigger. So you can only judge that the scroll bar is rolled up and down. About mobile phone gestures, the following article will be introduced, welcome attention!
2, by rolling down to let the bottom of the navigation display or so, Android above the browser can be, but Apple Safari will flash a flash, because Apple Safari automatically has a bounce effect, causing the event to repeat, the solution is to roll down a distance, scroll to a certain distance after the return is roll up or roll.
Simply judging the direction of the scroll bar
JS Code
- function Scroll (FN) {
- var beforescrolltop = Document.body.scrollTop,
- fn = fn | | function () {};
- Window.addeventlistener ("scroll", function () {
- var afterscrolltop = Document.body.scrollTop,
- Delta = afterscrolltop-beforescrolltop;
- if (delta = = 0) return false;
- fn (Delta > 0?) "Down ": "up");
- Beforescrolltop = Afterscrolltop;
- }, false);
- }
Call Method:
JS Code
- Scroll (function (direction) {Console.log (direction)});
Above method phone Apple browser event will bounce, workaround and code to improve JS code
- Scrolldirect: function (fn) {
- var beforescrolltop = Document.body.scrollTop;
- fn = fn | | function () {
- };
- Window.addeventlistener ("scroll", function (event) {
- Event = Event | | window.event;
- var afterscrolltop = Document.body.scrollTop;
- Delta = afterscrolltop-beforescrolltop;
- Beforescrolltop = Afterscrolltop;
- var scrolltop = $ (this). scrolltop ();
- var scrollheight = $ (document). Height ();
- var windowheight = $ (this). Height ();
- if (scrolltop + windowheight > scrollHeight-10) { //scroll to bottom execution event
- fn (' up ');
- return;
- }
- if (Afterscrolltop < | | afterscrolltop > $ (document.body). height-10) {
- fn (' up ');
- } Else {
- if (Math.Abs (delta) <) {
- return false;
- }
- fn (Delta > 0?) "Down ": "up");
- }
- }, false);
- }
Call Method:
JS Code
- var upflag=1;
- var downflag= 1;
- //scroll Slide, slide up and slide only once!
- Crolldirect (function (direction) {
- if (Direction = = "Down") {
- if (downflag) {
- $ (". Footer_wrap"). Slideup (200);
- Downflag = 0;
- Upflag = 1;
- }
- }
- if (Direction = = "Up") {
- if (upflag) {
- $ (". Footer_wrap"). Slidedown (200);
- Downflag = 1;
- Upflag = 0;
- }
- }
- });
Scroll bar Scroll to the bottom and head to judge
In fact, I have the above function has been judged, the following list! Look at the following function!
JS Code
- Bottomjumppage: function () {
- var scrolltop = $ (this). scrolltop ();
- var scrollheight = $ (document). Height ();
- var windowheight = $ (this). Height ();
- if (scrolltop + windowheight = = scrollheight) { //scroll to bottom execution event
- Console.dir ("I went to the bottom");
- }
- if (scrolltop = = 0) { //scroll to the head of the execution event
- Console.dir ("I went to the head");
- }
- }
Call Method:
JS Code
$ (window). Scroll (bottomjumppage);
jquery determines whether the page scroll bar (scroll) is rolled up or down and scrolled to the head or bottom