-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.textscroller.js
115 lines (107 loc) · 4.36 KB
/
jquery.textscroller.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
*
* Text Scroller - jQuery plugin for scroling div
* Copyright (c) 2014 Dmitrij Waśkowski
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* https://github.com/dwaskowski/jquery_textscroller
*
* Version: 1.0
*
*/
!function(e, t, o, n) {
e.fn.textscroller = function() {
var thisHtml = $(this).html();
$(this).html('');
var inner = $('<div>').html(thisHtml).appendTo($(this));
var tsWraperHeight = $(this).outerHeight();
var tsInnerHeight = $(inner).outerHeight();
var tsSliderWraperHeight = $('.ts-scroller-wraper').outerHeight();
if (tsWraperHeight<tsInnerHeight) {
var tsSliderHeight = Math.round((100/(tsInnerHeight/tsWraperHeight)/100)*tsSliderWraperHeight);
$('.ts-scroller-wraper > div').css('height', tsSliderHeight+'px');
}
var tsMaxInterval = tsSliderWraperHeight-tsSliderHeight;
var tsDifference = (tsInnerHeight-tsWraperHeight)/tsMaxInterval;
var tsSliderDrag = false, tsSliderTop = 0, tsMouseY = 0;
$('.ts-scroller-wraper > div').on({
'mousedown': function(e) {
if (!tsSliderDrag) {
tsSliderDrag = true;
tsMouseY = e.pageY;
}
}
})
$('.ts-scroller-wraper').on({
'mousemove': function(e) {
if (tsSliderDrag) {
var tsSliderTopModify = tsSliderTop + (e.pageY-tsMouseY);
if(tsSliderTopModify<0) {
tsSliderTopModify = 0;
}
if(tsSliderTopModify>tsMaxInterval) {
tsSliderTopModify = tsMaxInterval;
}
$(this).find('div').css('margin-top', tsSliderTopModify+'px');
var innerTop = (tsSliderTopModify*tsDifference*-1);
$(inner).css('margin-top',innerTop+'px');
}
},
'mouseup': function(e) {
if (tsSliderDrag) {
tsSliderDrag = false;
var tsSliderTopModify = tsSliderTop + (e.pageY-tsMouseY);
if(tsSliderTopModify<0) {
tsSliderTopModify = 0;
}
if(tsSliderTopModify>tsMaxInterval) {
tsSliderTopModify = tsMaxInterval;
}
tsSliderTop = tsSliderTopModify;
$(this).find('div').css('margin-top', tsSliderTopModify+'px');
var innerTop = (tsSliderTopModify*tsDifference*-1);
$(inner).css('margin-top',innerTop+'px');
}
},
'click': function(e) {
if (!tsSliderDrag) {
if(e.pageY < tsSliderTop) {
var tsSliderTopModify = tsSliderTop - 10;
} else if (e.pageY > (tsSliderTop+tsSliderHeight)) {
var tsSliderTopModify = tsSliderTop + 10;
} else {
return;
}
if(tsSliderTopModify<0) {
tsSliderTopModify = 0;
}
if(tsSliderTopModify>tsMaxInterval) {
tsSliderTopModify = tsMaxInterval;
}
tsSliderTop = tsSliderTopModify;
$(this).find('div').css('margin-top', tsSliderTopModify+'px');
var innerTop = (tsSliderTopModify*tsDifference*-1);
$(inner).css('margin-top',innerTop+'px');
}
}
});
$(o).on({
'mouseup': function(e) {
if (tsSliderDrag) {
tsSliderDrag = false;
var tsSliderTopModify = tsSliderTop + (e.pageY-tsMouseY);
if(tsSliderTopModify<0) {
tsSliderTopModify = 0;
}
if(tsSliderTopModify>tsMaxInterval) {
tsSliderTopModify = tsMaxInterval;
}
tsSliderTop = tsSliderTopModify;
}
}
});
};
}(jQuery, window, document);