Skip to content

Commit d367557

Browse files
committed
Fix scrollTop in firefox
1 parent 0ba780e commit d367557

File tree

5 files changed

+87
-5
lines changed

5 files changed

+87
-5
lines changed

examples/horizontal/css/main.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#app {
2+
font-size: 35px;
3+
}
4+
5+
body, html {
6+
max-height: 100%;
7+
margin: 0;
8+
}
9+
10+
body {
11+
padding: 20px;
12+
}
13+
14+
ul {
15+
margin: 0;
16+
}
17+
18+
li {
19+
display: inline-block;
20+
padding: 5px;
21+
background: lightgray;
22+
}
23+
24+
li + li {
25+
margin-left: 40px;
26+
}

examples/horizontal/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
6+
<meta name="description" content="Cycle.js example - Sortable"/>
7+
<link rel="stylesheet" href="css/main.css" type="text/css">
8+
<title>Cycle.js example - Sortable</title>
9+
</head>
10+
<body>
11+
<div id="app"></div>
12+
<script src="./index.js"></script>
13+
</body>
14+
</html>

examples/horizontal/src/index.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import xs, { Stream } from 'xstream';
2+
import { run } from '@cycle/run';
3+
import { ul, li, div, h3, makeDOMDriver, DOMSource, VNode } from '@cycle/dom';
4+
5+
import { makeSortable } from '../../../src/makeSortable';
6+
7+
type Sources = {
8+
DOM : DOMSource;
9+
};
10+
11+
type Sinks = {
12+
DOM : Stream<VNode>;
13+
};
14+
15+
function main({ DOM } : Sources) : Sinks
16+
{
17+
const vdom$ : Stream<VNode> = xs.of(
18+
div([
19+
h3('Horizontal too!'),
20+
ul('.ul', [
21+
li('.li', '', ['Option 1']),
22+
li('.li', '', ['Option 2']),
23+
li('.li', '', ['Option 3']),
24+
li('.li', '', ['Option 4']),
25+
li('.li', '', ['Option 5']),
26+
li('.li', '', ['Option 6']),
27+
])
28+
])
29+
)
30+
.compose(makeSortable(DOM, {
31+
parentSelector: '.ul'
32+
}));
33+
34+
return {
35+
DOM: vdom$
36+
};
37+
}
38+
39+
run(main, {
40+
DOM: makeDOMDriver('#app')
41+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
"build:examples": "tsc",
1010
"documentation": "typedoc --out docs src && cp-cli .nojekyll docs/.nojekyll",
1111
"prepublish": "npm run build && npm run documentation",
12-
"examples": "npm run build:examples && npm run examples:simple && npm run examples:parentSelector && npm run examples:updateEvent",
12+
"examples": "npm run build:examples && npm run examples:simple && npm run examples:horizontal && npm run examples:parentSelector && npm run examples:updateEvent",
1313
"examples:simple": "browserify build/examples/simple/src/index.js -o examples/simple/index.js && open-cli examples/simple/index.html",
14+
"examples:horizontal": "browserify build/examples/horizontal/src/index.js -o examples/horizontal/index.js && open-cli examples/horizontal/index.html",
1415
"examples:parentSelector": "browserify build/examples/parentSelector/src/index.js -o examples/parentSelector/index.js && open-cli examples/parentSelector/index.html",
1516
"examples:updateEvent": "browserify build/examples/updateEvent/src/index.js -o examples/updateEvent/index.js && open-cli examples/updateEvent/index.html"
1617
},

src/helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export function getGhostStyle(event : MouseEvent, mouseOffset : MouseOffset, ite
104104
const itemRect : ClientRect = item.getBoundingClientRect();
105105
return 'z-index: 5; margin: 0; pointer-events: none; position: absolute; width: '
106106
+ itemRect.width + 'px; ' + 'height: ' + itemRect.height + 'px; top: '
107-
+ (event.clientY + mouseOffset.y + document.body.scrollTop) + 'px; left: '
108-
+ (event.clientX + mouseOffset.x + document.body.scrollLeft) + 'px;';
107+
+ (event.clientY + mouseOffset.y + window.screenY) + 'px; left: '
108+
+ (event.clientX + mouseOffset.x + window.scrollX) + 'px;';
109109
}
110110

111111
/**
@@ -116,8 +116,8 @@ export function updateGhostStyle(event : MouseEvent, mouseOffset : MouseOffset,
116116
const prevStyle : string = ghost.getAttribute('style');
117117

118118
return prevStyle.substring(0, prevStyle.indexOf(' top:')) + ' top: '
119-
+ (event.clientY + mouseOffset.y + document.body.scrollTop) + 'px; left: '
120-
+ (event.clientX + mouseOffset.x + document.body.scrollLeft) + 'px;';
119+
+ (event.clientY + mouseOffset.y + window.scrollY) + 'px; left: '
120+
+ (event.clientX + mouseOffset.x + window.scrollX) + 'px;';
121121
}
122122

123123
/**

0 commit comments

Comments
 (0)