-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptr.js
43 lines (37 loc) · 1020 Bytes
/
ptr.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
// Made by Rosu Lucian Adrian - http://alurosu.com/
var y;
var scrolling = false;
var doResult = false;
function jqPTR(id, callback) {
$('#' + id).on('vmousemove', function(e) {
if ($('body').scrollTop() == 0 && e.pageY > y && scrolling) {
var dif = $('#ptr .loading'). height() - (e.pageY - y);
if (dif >= 0) {
doResult = false;
dif = '-' + dif + 'px';
$('#ptr .loading').css({marginTop: dif});
} else {
doResult = true;
$('#ptr .loading').css({marginTop: '0px'});
}
e.preventDefault();
}
})
.on('vmousedown', function(e) {
scrolling = true;
y = e.pageY;
})
.on('vmouseup', function(e) {
scrolling = false;
if (doResult) {
doResult = false;
y = $(this).height();
$('#ptr .loading').html('Loading..');
callback();
} else jqPTR_refresh();
});
}
function jqPTR_refresh() {
var dif = '-' + ($('#ptr .loading').height() + 3) + 'px';
$('#ptr .loading').animate({marginTop: dif}, function(){$(this).html('Pull to refresh.')});
}