Skip to content

Commit 2aab98a

Browse files
authored
Merge pull request #2050 from javascript-tutorial/paroche-patch-19
Various minor syntax and punctuation changes
2 parents 1599dec + 4ff6eb4 commit 2aab98a

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

2-ui/3-event-details/6-pointer-events/article.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Pointer events
22

3-
Pointer events are a modern way to handle input from a variety of pointing devices, such as a mouse, a pen/stylus, a touchscreen and so on.
3+
Pointer events are a modern way to handle input from a variety of pointing devices, such as a mouse, a pen/stylus, a touchscreen, and so on.
44

55
## The brief history
66

@@ -16,13 +16,13 @@ Let's make a small overview, so that you understand the general picture and the
1616

1717
- To solve these issues, the new standard Pointer Events was introduced. It provides a single set of events for all kinds of pointing devices.
1818

19-
As of now, [Pointer Events Level 2](https://www.w3.org/TR/pointerevents2/) specification is supported in all major browsers, while the [Pointer Events Level 3](https://w3c.github.io/pointerevents/) is in the works. Unless you code for Internet Explorer 10 or Safari 12 and below, there's no point in using mouse or touch events any more. We can switch to pointer events.
19+
As of now, [Pointer Events Level 2](https://www.w3.org/TR/pointerevents2/) specification is supported in all major browsers, while [Pointer Events Level 3](https://w3c.github.io/pointerevents/) is in the works. Unless you code for Internet Explorer 10, or for Safari 12 or below, there's no point in using mouse or touch events any more -- we can switch to pointer events.
2020

21-
That said, there are important peculiarities, one should know them to use them correctly and avoid surprises. We'll pay attention to them in this article.
21+
That said, there are important peculiarities one should know them to use them correctly and avoid surprises. We'll make note of them in this article.
2222

2323
## Pointer event types
2424

25-
Pointer events are named similar to mouse events:
25+
Pointer events are named similarly to mouse events:
2626

2727
| Pointer Event | Mouse event |
2828
|---------------|-------------|
@@ -42,25 +42,25 @@ As we can see, for every `mouse<event>`, there's a `pointer<event>` that plays a
4242
```smart header="Replacing `mouse<event>` with `pointer<event>` in our code"
4343
We can replace `mouse<event>` events with `pointer<event>` in our code and expect things to continue working fine with mouse.
4444

45-
The support for touch devices will also "magically" improve, but we'll probably need to add `touch-action: none` rule in CSS. See the details below in the section about `pointercancel`.
45+
The support for touch devices will also "magically" improve, but we'll probably need to add `touch-action: none` in CSS. See the details below in the section about `pointercancel`.
4646
```
4747
4848
## Pointer event properties
4949
50-
Pointer events have the same properties as mouse events, such as `clientX/Y`, `target` etc, plus some extra:
50+
Pointer events have the same properties as mouse events, such as `clientX/Y`, `target`, etc., plus some others:
5151
5252
- `pointerId` - the unique identifier of the pointer causing the event.
5353
54-
Allows to handle multiple pointers, such as a touchscreen with stylus and multi-touch (explained below).
55-
- `pointerType` - the pointing device type, must be a string, one of: "mouse", "pen" or "touch".
54+
Allows us to handle multiple pointers, such as a touchscreen with stylus and multi-touch (explained below).
55+
- `pointerType` - the pointing device type. Must be a string, one of: "mouse", "pen" or "touch".
5656
5757
We can use this property to react differently on various pointer types.
5858
- `isPrimary` - `true` for the primary pointer (the first finger in multi-touch).
5959
60-
For pointers that measure a contact area and pressure, e.g. a finger on the touchscreen, the additional properties can be useful:
60+
For pointers that measure contact area and pressure, e.g. a finger on the touchscreen, the additional properties can be useful:
6161
62-
- `width` - the width of the area where the pointer touches the device. Where unsupported, e.g. for mouse it's always `1`.
63-
- `height` - the height of the area where the pointer touches the device. Where unsupported, always `1`.
62+
- `width` - the width of the area where the pointer touches the device. Where unsupported, e.g. for a mouse, it's always `1`.
63+
- `height` - the height of the area where the pointer touches the device. Where unsupported, it's always `1`.
6464
- `pressure` - the pressure of the pointer tip, in range from 0 to 1. For devices that don't support pressure must be either `0.5` (pressed) or `0`.
6565
- `tangentialPressure` - the normalized tangential pressure.
6666
- `tiltX`, `tiltY`, `twist` - pen-specific properties that describe how the pen is positioned relative the surface.
@@ -69,11 +69,11 @@ These properties aren't very well supported across devices, so they are rarely u
6969
7070
## Multi-touch
7171
72-
One of the things that mouse events totally don't support is multi-touch: a user can touch them in several places at once on their phone or tablet, or perform special gestures.
72+
One of the things that mouse events totally don't support is multi-touch: a user can touch in several places at once on their phone or tablet, or perform special gestures.
7373
74-
Pointer Events allow handling multi-touch with the help of `pointerId` and `isPrimary` properties.
74+
Pointer Events allow handling multi-touch with the help of the `pointerId` and `isPrimary` properties.
7575
76-
Here's what happens when a user touches a screen in one place, and then puts another finger somewhere else on it:
76+
Here's what happens when a user touches a screen in one place, then puts another finger somewhere else on it:
7777
7878
1. At the first touch:
7979
- `pointerdown` with `isPrimary=true` and some `pointerId`.
@@ -91,7 +91,7 @@ Here's the demo that logs `pointerdown` and `pointerup` events:
9191
9292
[iframe src="multitouch" edit height=200]
9393
94-
Please note: you must be using a touchscreen device, such as a phone or a tablet to actually see the difference. For single-touch devices, such as a mouse, there'll be always same `pointerId` with `isPrimary=true`, for all pointer events.
94+
Please note: you must be using a touchscreen device, such as a phone or a tablet, to actually see the difference. For single-touch devices, such as a mouse, there'll be always same `pointerId` with `isPrimary=true`, for all pointer events.
9595
```
9696

9797
## Event: pointercancel
@@ -109,7 +109,7 @@ We'll demonstrate `pointercancel` on a practical example to see how it affects u
109109

110110
Let's say we're impelementing drag'n'drop for a ball, just as in the beginning of the article <info:mouse-drag-and-drop>.
111111

112-
Here are the flow of user actions and corresponding events:
112+
Here is the flow of user actions and the corresponding events:
113113

114114
1) The user presses the mouse button on an image, to start dragging
115115
- `pointerdown` event fires
@@ -134,7 +134,7 @@ We'd like to implement our own drag'n'drop, so let's tell the browser not to tak
134134
We need to do two things:
135135

136136
1. Prevent native drag'n'drop from happening:
137-
- Can do it by setting `ball.ondragstart = () => false`, just as described in the article <info:mouse-drag-and-drop>.
137+
- We can do this by setting `ball.ondragstart = () => false`, just as described in the article <info:mouse-drag-and-drop>.
138138
- That works well for mouse events.
139139
2. For touch devices, there are also touch-related browser actions. We'll have problems with them too.
140140
- We can prevent them by setting `#ball { touch-action: none }` in CSS.
@@ -218,12 +218,12 @@ Pointer events allow handling mouse, touch and pen events simultaneously.
218218

219219
Pointer events extend mouse events. We can replace `mouse` with `pointer` in event names and expect our code to continue working for mouse, with better support for other device types.
220220

221-
Remember to set `touch-events: none` in CSS for elements that we engage, otherwise the browser hijacks many types of touch interactions and pointer events won't be generated.
221+
Remember to set `touch-events: none` in CSS for elements that we engage, otherwise the browser will hijack many types of touch interactions, and pointer events won't be generated.
222222

223223
Additional abilities of Pointer events are:
224224

225225
- Multi-touch support using `pointerId` and `isPrimary`.
226-
- Device-specific properties, such as `pressure`, `width/height` and others.
226+
- Device-specific properties, such as `pressure`, `width/height`, and others.
227227
- Pointer capturing: we can retarget all pointer events to a specific element until `pointerup`/`pointercancel`.
228228

229-
As of now, pointer events are supported in all major browsers, so we can safely switch to them, if IE10- and Safari 12- are not needed. And even with those browsers, there are polyfills that enable the support of pointer events.
229+
As of now, pointer events are supported in all major browsers, so we can safely switch to them, as long as IE10- and Safari 12- are not needed. And even with those browsers, there are polyfills that enable the support of pointer events.

0 commit comments

Comments
 (0)