Skip to content

Commit a06376d

Browse files
committed
micro is now 410 bytes
1 parent a04f4b6 commit a06376d

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dragscroll
22
==========
33

4-
Dragscroll is a tiny javascript library (425 bytes minified) which
4+
Dragscroll is a tiny javascript library (410 bytes minified) which
55
enables scrolling via holding the mouse button (drag-n-drop style,
66
[online demo](http://asvd.github.io/dragscroll/)).
77

@@ -10,7 +10,7 @@ enables scrolling via holding the mouse button (drag-n-drop style,
1010

1111

1212
Download the
13-
[distribution](https://github.com/asvd/dragscroll/releases/download/v0.0.2/dragscroll-0.0.2.tar.gz),
13+
[distribution](https://github.com/asvd/dragscroll/releases/download/v0.0.3/dragscroll-0.0.3.tar.gz),
1414
unpack it and load the `dragscroll.js` or `dragscroll_micro.js`:
1515

1616
```html
@@ -35,7 +35,7 @@ the users (or even `cursor: grab;` in case the content is not a text).
3535

3636
### Micro verison
3737

38-
Located in `dragscroll_micro.js`, its size is 425 bytes, and it just works.
38+
Located in `dragscroll_micro.js`, its size is 410 bytes, and it just works.
3939

4040

4141
### Full-featured verison

dragscroll.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @fileoverview dragscroll - scroll area by dragging
3-
* @version 0.0.2
3+
* @version 0.0.3
44
*
55
* @license MIT, see http://github.com/asvd/intence
66
* @copyright 2015 asvd <heliosframework@gmail.com>

dragscroll_micro.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
window.addEventListener("load", function() {
22
var addEventListener = 'addEventListener';
3-
var clientX = 'clientX';
4-
var clientY = 'clientY';
53
var elems = document.getElementsByClassName('dragscroll');
6-
for (var i = 0; i < elems.length; i++) {
4+
for (var i = 0; i < elems.length;) {
75
(function(elem, lastClientX, lastClientY, pushed) {
86
elem[addEventListener]('mousedown', function(e) {
9-
pushed = true;
10-
lastClientX = e[clientX];
11-
lastClientY = e[clientY];
7+
pushed = 1;
8+
lastClientX = e.clientX;
9+
lastClientY = e.clientY;
1210

1311
e.preventDefault();
1412
e.stopPropagation();
15-
}, false);
13+
}, 0);
1614

1715
window[addEventListener]('mousemove', function(e) {
1816
if (pushed) {
19-
elem.scrollLeft -= (e[clientX] - lastClientX);
20-
elem.scrollTop -= (e[clientY] - lastClientY);
21-
22-
lastClientX = e[clientX];
23-
lastClientY = e[clientY];
17+
elem.scrollLeft -= (- lastClientX + (lastClientX=e.clientX));
18+
elem.scrollTop -= (- lastClientY + (lastClientY=e.clientY));
2419
}
25-
}, false);
20+
}, 0);
2621

2722
window[addEventListener]('mouseup', function(){
28-
pushed = false;
29-
}, false);
23+
pushed = 0;
24+
}, 0);
3025

31-
})(elems[i]);
26+
})(elems[i++]);
3227
}
33-
}, false);
28+
}, 0);
3429

0 commit comments

Comments
 (0)