📜 ⬆️ ⬇️

Mobile web development: gestures, frameworks, numbers

Continuing the theme of web development of mobile sites and applications for mobile devices, one cannot but touch upon such a topic as the Framework for manipulating DOM and sending asynchronous requests.
The standard on the desktop has long been jQuery, but it is no good for developing for a mobile platform. Let's see how jQuery is friendly with mobile devices.


jQuery and mobile devices.


The first problem with jQuery is tachi. Handling a tache by the 'click' event is not the best idea. Due to the fact that mobile browsers have to support the click event, we can do it, but at a high price. On mobile devices, the click event is not called until 300ms has passed after the user has touched the screen, to determine whether it is scrolling or double tap or something else and the click event works, and this may seem insignificant, but the reaction to another action through others 300ms will cause a noticeable delay.

To avoid this, you can use tap-events that are supported by jQuery satellite - jQuery Mobile. But jQuery Mobile is also not the best solution. First, it is very large in size, as well as jQuery and even services that allow you to cut jQuery parts do not help to reduce its size sufficiently. The second serious drawback is the lack of support for gestures.
')

Gestures in theory.


Mobile version of WebKit (iOS, Android) supports the following events:

So, to crack the svayp we need the following code:
var touchstartX = 0; var touchstartY = 0; var touchendX = 0; var touchendY = 0; var gesuredZone = document.getElementById('gesuredZone'); gesuredZone.addEventListener('touchstart', function(event) { touchstartX = event.screenX; touchstartY = event.screenY; }, false); gesuredZone.addEventListener('touchend', function(event) { touchendX = event.screenX; touchendY = event.screenY; handleGesure(); }, false); function handleGesure() { var swiped = 'swiped: '; if (touchendX < touchstartX) { alert(swiped + 'left!'); } if (touchendX > touchstartX) { alert(swiped + 'right!'); } if (touchendY < touchstartY) { alert(swiped + 'down!'); } if (touchendY > touchstartY) { alert(swiped + 'left!'); } if (touchendY == touchstartY) { alert('tap!'); } } 

A working example:
http://jsfiddle.net/sagens/zNvtL/2/


Because of the complexity of handling gestures, you can refer to jQuery alternatives that support gestures

JQuery Alternatives


In search of alternatives, you can put forward the following requirements:
  1. DOM manipulations
  2. Gesture processing
  3. Asynchronous requests
  4. Small size


Frameworks


Quo.JS.





Zepto.JS






Libraries


Hammer.JS




Jester



Thumbs.JS




Source: https://habr.com/ru/post/178611/


All Articles