Skip to content

Commit 9d5cb87

Browse files
author
Aleksey Novikov
committed
Fixed IE scrollTo
1 parent 733eb31 commit 9d5cb87

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hook-scroll",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Router-async hook scroll",
55
"keywords": [
66
"router-async",

src/main.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
const storage = [];
22

3+
const scrollTo = ($el, top, left) => {
4+
if($el) {
5+
if($el.scrollTo) {
6+
$el.scrollTo(top, left);
7+
} else {
8+
$el.scrollTop = top;
9+
$el.scrollLeft = left;
10+
}
11+
}
12+
};
13+
314
module.exports = ({ history, elementId, reset = true, limit = 20 }) => {
415
const $el = elementId ? document.getElementById(elementId) : window;
516

@@ -38,16 +49,12 @@ module.exports = ({ history, elementId, reset = true, limit = 20 }) => {
3849
position = storage.pop();
3950
}
4051

41-
if($el && $el.scrollTo) {
42-
$el.scrollTo(...position);
43-
}
52+
scrollTo($el, ...position);
4453

4554
break;
4655
case 'PUSH':
4756
if(reset || (resetScroll && resetOnAction === 'PUSH')) {
48-
if($el && $el.scrollTo) {
49-
$el.scrollTo(...position);
50-
}
57+
scrollTo($el, ...position);
5158
}
5259

5360
break;

0 commit comments

Comments
 (0)