Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 2b815a0

Browse files
committed
just only chrome and touch. using overscroll-behavior
1 parent 88bd117 commit 2b815a0

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# prevent-pull-refresh
2+
23
Preventing the pull-to-refresh effect browser on mobile
34

45
[![NPM version](https://img.shields.io/npm/v/prevent-pull-refresh.svg)](https://www.npmjs.com/package/prevent-pull-refresh)
56
[![NPM monthly download](https://img.shields.io/npm/dm/prevent-pull-refresh.svg)](https://www.npmjs.com/package/prevent-pull-refresh)
67

78
## Document
8-
https://docs.google.com/document/d/12Ay4s3NWake8Qd6xQeGiYimGJ_gCe0UMDZKwP9Ni4m8
99

10-
![pull-refresh](https://lh3.googleusercontent.com/xCQZK2gd3R0pNmTXINDQkS4OXiPQa_I2H2i-W6frt40F17gnAjqpkpCXJeyroDcNzzhYZwHtApBSoNCt5inU1dYmgTSzdTLNBxVNF8GjoQLLdH51RzfNPrgVm21blWkgM_xkQKI=s300)
10+
https://docs.google.com/document/d/12Ay4s3NWake8Qd6xQeGiYimGJ_gCe0UMDZKwP9Ni4m8
11+
https://developers.google.com/web/updates/2017/11/overscroll-behavior
12+
13+
![pull-refresh](https://lh3.googleusercontent.com/xCQZK2gd3R0pNmTXINDQkS4OXiPQa_I2H2i-W6frt40F17gnAjqpkpCXJeyroDcNzzhYZwHtApBSoNCt5inU1dYmgTSzdTLNBxVNF8GjoQLLdH51RzfNPrgVm21blWkgM_xkQKI=s300)
1114

1215
## Installation
1316

@@ -18,13 +21,15 @@ $ yarn add prevent-pull-refresh
1821
## Usage
1922

2023
```js
21-
import 'prevent-pull-refresh'
24+
import 'prevent-pull-refresh';
2225
```
26+
2327
or
2428

2529
```html
2630
<script src="//unpkg.com/prevent-pull-refresh"></script>
2731
```
2832

2933
## License
30-
MIT © [Nghiệp](http://nghiepit.pro)
34+
35+
MIT © [Nghiệp](http://nghiepit.pro)

index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
(() => {
2+
const isChrome = window.chrome || navigator.userAgent.match('CriOS');
3+
const isTouch = 'ontouchstart' in document.documentElement;
4+
5+
if (!isChrome || !isTouch) {
6+
return;
7+
}
8+
9+
let supportsOverscroll = false;
10+
let supportsPassive = false;
211
let lastTouchY = 0;
312
let maybePrevent = false;
4-
let supportsPassive = false;
513

614
try {
15+
if (CSS.supports('overscroll-behavior-y', 'contain')) {
16+
supportsOverscroll = true;
17+
}
18+
719
addEventListener('test', null, {
820
get passive() {
921
supportsPassive = true;
1022
},
1123
});
1224
} catch (e) {}
1325

26+
if (supportsOverscroll) {
27+
return (document.body.style.overscrollBehaviorY = 'contain');
28+
}
29+
1430
const setTouchStartPoint = event => {
1531
lastTouchY = event.touches[0].clientY;
1632
};

index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prevent-pull-refresh",
3-
"version": "0.0.2",
3+
"version": "1.0.0",
44
"description": "Preventing the pull-to-refresh effect browser on mobile",
55
"main": "index.min.js",
66
"scripts": {
@@ -14,7 +14,7 @@
1414
},
1515
"repository": "https://github.com/tronghiep92/prevent-pull-refresh",
1616
"author": "Nghiệp <me@nghiepit.pro>",
17-
"homepage": "http://nghiepit.pro",
17+
"homepage": "https://github.com/tronghiep92/prevent-pull-refresh",
1818
"keywords": [
1919
"pull refresh",
2020
"refresh",

0 commit comments

Comments
 (0)