


Introduction to the use of advanced gestures in Javascript_html5 tutorial skills
The newly added recognition support for advanced user input in IE10, for example: register a click operation, and through the sentence addEventListener, you can know which device the current user clicks on, whether it is a finger click or a mouse click. Or click with a stylus (tablet devices all come with a stylus).
MyCanvas.addEventListener( "MSPointerDown"
, MyBack, false); function MyBack(e) { ; >
The above code can identify which device the current user clicks on, and determine it through e.pointerType in the callback method. The mouse is 4, the stylus is 3, and the finger is 2. As for what kind of device the value 1 is, it remains to be studied.
Another thing to note is that if you want to add recognition of input devices in JavaScript, the registered method events are also a little different.
The event added by
addEventListener is MSPointerDown In IE10, for such multiple device recognition, finger clicks are prioritized, provided that the normal click function is not affected. However, IE10 not only recognizes the user's input device but also supports a lot of advanced gestures The following is a demonstration of IE10 advanced gesture support
Create Gesture Object
The first step in handling gestures in your website is to instantiate a gesture object.
<span style="COLOR: blue">var<p> myGesture = <span style="COLOR: blue">new</span></p> MSGesture();</span>
Next, provide a target element for the gesture. The browser will trigger the gesture event on the element. At the same time, this element can also determine the coordinate space of the event.
elm = document.getElementById(<span style="COLOR: maroon">"someElement"</span>
<span style="COLOR: blue">var</span> myGesture = <span style="COLOR: blue">new</span> MSGesture();
elm.addEventListener(<span style="COLOR: maroon">"MSGestureChange"</span>
Finally, tell the gesture object which pointers to handle during gesture recognition.
elm.addEventListener(<span style="COLOR: maroon">"MSPointerDown"</span>, <span style="COLOR: blue">function</span> (evt) {
<span style="COLOR: rgb(0,100,0)">// adds the current mouse, pen, or touch contact for gesture recognition</span>
myGesture.addPointer(evt.pointerId);
});
Note: Don't forget that you need to use –ms-touch-action
to configure the element to prevent it from performing default touch actions (e.g., pan and zoom) and to provide pointer events for input.
Once a gesture object has a valid target and at least one pointer added, it will start firing gesture events. Gesture events can be divided into two types: static gestures (for example, click or hold) and dynamic gestures (for example, pinch, rotate, and swipe).
ClickThe most basic gesture recognition is click. When a click is detected, the MSGestureTap
event will be fired on the target element of the gesture object. Unlike click events, tap gestures can only be triggered when the user touches, presses a mouse button, or touches with a stylus without moving. This is often useful if you want to distinguish between a user clicking on an element and a user dragging it.
The long press gesture refers to an operation in which the user touches the screen with one finger, holds it for a moment and lifts it without moving. During a long press interaction, the MSGestureHold
event will be triggered multiple times for various states of the gesture:
element.addEventListener("MSGestureHold", handleHold);
function handleHold(evt) {
if (evt.detail & evt.MSGESTURE_FLAG_BEGIN) {
// Begin signals the start of a gesture. For the Hold gesture, this means the user has been holding long enough in place that the gesture will become a complete press & hold if the finger is lifted.
}
if (evt.detail & evt.MSGESTURE_FLAG_END) {
// End signals the end of the gesture.
}
if (evt.detail & evt.MSGESTURE_FLAG_CANCEL) {
// Cancel signals the user started the gesture but canceled it. For hold, this occurs when the user drags away before lifting. This flag is sent together with the End flag, signaling the gesture recognition is complete.
}
}
Dynamic gestures (pinch, rotate, swipe and drag)
Dynamic gestures (e.g. pinch or rotate) are reported as transitions, much like CSS 2D transitions. Dynamic gestures can trigger three events: MSGestureStart
, MSGestureChange
(which fires repeatedly as the gesture continues), and MSGestureEnd
. Each event contains information about scaling (shrinking), rotation, transformation, and speed.
Since dynamic gestures are reported as transitions, it's easy to manipulate elements like photos or puzzles using MSGesture
that includes CSS 2D transitions. For example, you can enable scaling, rotating, and dragging elements via:
targetElement.addEventListener("MSGestureChange", manipulateElement);
function manipulateElement(e) {
// Uncomment the following code if you want to disable the built-in inertia provided by dynamic gesture recognition
// if (e.detail == e.MSGESTURE_FLAG_INERTIA)
// return;
var m = new MSCSSMatrix(e.target.style.transform); // Get the latest CSS transform on the element
e.target.style.transform = m
.translate(e.offsetX, e.offsetY) // Move the transform origin under the center of the gesture
.rotate(e. rotation * 180 / Math.PI) // Apply Rotation
.scale(e.scale) // Apply Scale
.translate(e.translationX, e.translationY) // Apply Translation
.translate( -e.offsetX, -e.offsetY); // Move the transform origin back
}
Dynamic gestures such as scaling and rotation can support mouse operations, which can be done by rotating This is achieved by using the CTRL or SHIFT modifier keys respectively while using the mouse wheel.

Best practices for H5 code include: 1. Use correct DOCTYPE declarations and character encoding; 2. Use semantic tags; 3. Reduce HTTP requests; 4. Use asynchronous loading; 5. Optimize images. These practices can improve the efficiency, maintainability and user experience of web pages.

Web standards and technologies have evolved from HTML4, CSS2 and simple JavaScript to date and have undergone significant developments. 1) HTML5 introduces APIs such as Canvas and WebStorage, which enhances the complexity and interactivity of web applications. 2) CSS3 adds animation and transition functions to make the page more effective. 3) JavaScript improves development efficiency and code readability through modern syntax of Node.js and ES6, such as arrow functions and classes. These changes have promoted the development of performance optimization and best practices of web applications.

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

The tools and frameworks that need to be mastered in H5 development include Vue.js, React and Webpack. 1.Vue.js is suitable for building user interfaces and supports component development. 2.React optimizes page rendering through virtual DOM, suitable for complex applications. 3.Webpack is used for module packaging and optimize resource loading.

HTML5hassignificantlytransformedwebdevelopmentbyintroducingsemanticelements,enhancingmultimediasupport,andimprovingperformance.1)ItmadewebsitesmoreaccessibleandSEO-friendlywithsemanticelementslike,,and.2)HTML5introducednativeandtags,eliminatingthenee

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool