toucher_util.js
2.29 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
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
var ToucherUtil = {
swipeList : function(selector, btnSelector){
var $list;
if(typeof selector === "string"){
$list = $(selector);
}else if(selector instanceof $){
$list = selector;
}else{
$list = $(selector);
}
var type = $list.attr("swipeType");
if(!type || type == ""){
type = "1";
}
$list.children("li").each(function(){
var $li = $(this);
if($li.attr('swipe_event') != "true"){
var liTouch = util.toucher($li[0]);
liTouch.on('swipeLeft',function(e){
var $theLi = $(this);
var pdFn = function(e){
e.preventDefault();
};
$theLi[0].addEventListener('touchmove', pdFn, false);
setTimeout(function(){
$theLi[0].removeEventListener("touchmove", pdFn, false);
}, 300);
//向左滑动时先复原其他已被划出的LI
$theLi.siblings("[is_swiped='true']").trigger("swipeRight");
var $slideBtnContainer = $(btnSelector, $theLi);
var w = $slideBtnContainer.width();
var $liContent = $theLi.children().eq(0);
if(type == "1"){
$liContent.css({
"-webkit-transform" : "translate3d(-"+w+"px, 0, 0)",
"transform" : "translate3d(-"+w+"px, 0, 0)"
});
$slideBtnContainer.addClass("show");
}else if(type == "2"){
$slideBtnContainer.addClass("show");
}
$theLi.attr("is_swiped", "true");
});
var rightFn = function(e){
var $theLi = $(this);
var pdFn = function(e){
e.preventDefault();
};
$theLi[0].addEventListener('touchmove', pdFn, false);
setTimeout(function(){
$theLi[0].removeEventListener("touchmove", pdFn, false);
}, 300);
var $slideBtnContainer = $(btnSelector, $theLi);
var $liContent = $theLi.children().eq(0);
var w = $slideBtnContainer.width();
if(type == "1"){
$slideBtnContainer.removeClass("show");
$liContent.css({
"-webkit-transform" : "translate3d(0, 0, 0)",
"transform" : "translate3d(0, 0, 0)"
});
}else if(type == "2"){
$slideBtnContainer.removeClass("show");
}
$theLi.removeAttr("is_swiped");
};
liTouch.on('swipeRight', rightFn);
$li.live('swipeRight', rightFn)
}
});
$list.children("li").attr("swipe_event", "true");
}
};