-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscrollhorizontal.js
More file actions
48 lines (37 loc) · 1.57 KB
/
scrollhorizontal.js
File metadata and controls
48 lines (37 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* SamsonJS plugin for scrolling horizontal block
*
* @param selectorWrapBlock block which react on mouse scroll
* @param selectorRotateBlock block which have to scroll
* @param shift it's value which affect to velocity scrolling
* if value < 0 then scroll will be from left to right
* if value > 0 then it is reverse direction
*/
var ScrollHorizontal = function(selectorWrapBlock, selectorRotateBlock, shift) {
var shift = shift || -1;
//Set handler on mouse scroll
selectorWrapBlock.mousewheel(function(p1,p2,event){
//Current value of rotation
var scrollSize = parseInt(selectorRotateBlock.scrollLeft());
//Solved value of rotation
var newPosition = parseInt(shift * event.wheelDelta);
//Set new scroll value
selectorRotateBlock.scrollLeft(scrollSize+newPosition);
},true,true);
var touchStart = 0;
// Remember strarting position
selectorWrapBlock.DOMElement.addEventListener('touchstart', function(event) {
touchStart = event.touches[0].pageX;
});
// Change position of block
selectorWrapBlock.DOMElement.addEventListener('touchmove', function(event) {
// Get current shift on the event
var currentPosition = event.touches[0].pageX;
//Current value of rotation
var scrollSize = parseInt(selectorRotateBlock.scrollLeft());
//Solved value of rotation
var newPosition = parseInt(currentPosition - touchStart);
//Set new scroll value
selectorRotateBlock.scrollLeft(scrollSize-newPosition);
});
};