Skip to content

Commit

Permalink
just only chrome and touch. using overscroll-behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiepdev committed Dec 20, 2017
1 parent 88bd117 commit 2b815a0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# prevent-pull-refresh

Preventing the pull-to-refresh effect browser on mobile

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

## Document
https://docs.google.com/document/d/12Ay4s3NWake8Qd6xQeGiYimGJ_gCe0UMDZKwP9Ni4m8

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

![pull-refresh](https://lh3.googleusercontent.com/xCQZK2gd3R0pNmTXINDQkS4OXiPQa_I2H2i-W6frt40F17gnAjqpkpCXJeyroDcNzzhYZwHtApBSoNCt5inU1dYmgTSzdTLNBxVNF8GjoQLLdH51RzfNPrgVm21blWkgM_xkQKI=s300)

## Installation

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

```js
import 'prevent-pull-refresh'
import 'prevent-pull-refresh';
```

or

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

## License
MIT © [Nghiệp](http://nghiepit.pro)

MIT © [Nghiệp](http://nghiepit.pro)
18 changes: 17 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
(() => {
const isChrome = window.chrome || navigator.userAgent.match('CriOS');
const isTouch = 'ontouchstart' in document.documentElement;

if (!isChrome || !isTouch) {
return;
}

let supportsOverscroll = false;
let supportsPassive = false;
let lastTouchY = 0;
let maybePrevent = false;
let supportsPassive = false;

try {
if (CSS.supports('overscroll-behavior-y', 'contain')) {
supportsOverscroll = true;
}

addEventListener('test', null, {
get passive() {
supportsPassive = true;
},
});
} catch (e) {}

if (supportsOverscroll) {
return (document.body.style.overscrollBehaviorY = 'contain');
}

const setTouchStartPoint = event => {
lastTouchY = event.touches[0].clientY;
};
Expand Down
2 changes: 1 addition & 1 deletion index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prevent-pull-refresh",
"version": "0.0.2",
"version": "1.0.0",
"description": "Preventing the pull-to-refresh effect browser on mobile",
"main": "index.min.js",
"scripts": {
Expand All @@ -14,7 +14,7 @@
},
"repository": "https://github.com/tronghiep92/prevent-pull-refresh",
"author": "Nghiệp <[email protected]>",
"homepage": "http://nghiepit.pro",
"homepage": "https://github.com/tronghiep92/prevent-pull-refresh",
"keywords": [
"pull refresh",
"refresh",
Expand Down

0 comments on commit 2b815a0

Please sign in to comment.