Przeglądaj źródła

【提交内容】:手势的演示

wangyj18 9 lat temu
rodzic
commit
ad9a352651

+ 7 - 0
display-server/web/biz/img/plugin/hammer/circle-check.svg

@ -0,0 +1,7 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20">
3
<g stroke="#2ca02c" stroke-width="2.3" fill="#fff">
4
<circle cx="10" cy="10" r="8.5"/>
5
<path d="M5.2,10 8.5,13.4 14.8,7.2"/>
6
</g>
7
</svg>

BIN
display-server/web/biz/img/plugin/hammer/pan.png


BIN
display-server/web/biz/img/plugin/hammer/pano-1.jpg


BIN
display-server/web/biz/img/plugin/hammer/pano-2.jpg


BIN
display-server/web/biz/img/plugin/hammer/pano-3.jpg


BIN
display-server/web/biz/img/plugin/hammer/pinch.png


BIN
display-server/web/biz/img/plugin/hammer/press.png


BIN
display-server/web/biz/img/plugin/hammer/rotate.png


BIN
display-server/web/biz/img/plugin/hammer/swipe.png


BIN
display-server/web/biz/img/plugin/hammer/tap.png


+ 0 - 16
display-server/web/biz/js/plugin/gestures.js

@ -1,16 +0,0 @@
1
require(["domReady!","mobile","jcl","hammer"],function(doc, Mobile, $, Hammer) {
2
	
3
	$("#PanAndSwipe").tap(function(){
4
		Mobile.openPage("PanAndSwipe");
5
	});
6
	$("#TapAndPress").tap(function(){
7
		Mobile.openPage("TapAndPress");
8
	});
9
	$("#PinchAndRotate").tap(function(){
10
		Mobile.openPage("PinchAndRotate");
11
	});
12
	$("#Nested").tap(function(){
13
		Mobile.openPage("Nested");
14
	});
15
	
16
});

+ 112 - 0
display-server/web/biz/js/plugin/hammer.js

@ -0,0 +1,112 @@
1
require([ "domReady!", "mobile", "hammer", "jquery", "util" ], function(doc, Mobile, Hammer, jQuery) {
2
	new iScroll("content");
3
	
4
	// rotate
5
	var rotateHam = new Hammer($(".rotate")[0], {
6
		domEvents : true
7
	});
8
	var liveScale = 1;
9
	var currentRotation = 0;
10
	rotateHam.get('rotate').set({
11
		enable : true
12
	});
13
	jQuery(".rotate").on("rotate",function(e) {
14
		var rotation = currentRotation + Math.round(liveScale* e.originalEvent.gesture.rotation);
15
		$(this).find("img").css("transform", "rotate( " + rotation + "deg)");
16
		console.log("rotation = " + rotation);
17
	});
18
	jQuery(".rotate").on("rotateend", function(e) {
19
		currentRotation += Math.round(e.originalEvent.gesture.rotation);
20
	});
21

22
	// pinch
23
    var pinchHam = new Hammer($(".pinch")[0], {
24
    	domEvents : true
25
	});
26
	var width = 1900;
27
	var height = 400;
28
	var left = 950;
29
	var top = 220;
30
	pinchHam.get('pinch').set({
31
		enable : true
32
	});
33
	jQuery(".pinch").on("pinch", function(e) {
34
		if (width * e.originalEvent.gesture.scale >= 300) {
35
			jQuery(this).find("img").css({
36
				width : width * e.originalEvent.gesture.scale,
37
				"margin-left" : -left * e.originalEvent.gesture.scale,
38
				height : height * e.originalEvent.gesture.scale,
39
				"margin-top" : -top * e.originalEvent.gesture.scale
40
			});
41
		}
42
		console.log(e.originalEvent.gesture.scale);
43
	});
44
	jQuery(".pinch").on("pinchend", function(e) {
45
		width = width * e.originalEvent.gesture.scale;
46
		height = height * e.originalEvent.gesture.scale;
47
		left = left * e.originalEvent.gesture.scale;
48
		top = top * e.originalEvent.gesture.scale;
49
		console.log(width);
50
	});
51
	
52
	// press
53
	new Hammer($( ".press")[0], {
54
      domEvents: true
55
    });
56
    $(".press").on("press", function(e) {
57
       $(".demo-overlay").toggle();
58
    });
59
    
60
    // pan
61
	var panImg, panMargin;
62
	new Hammer($(".pan")[0], {
63
		domEvents : true
64
	});
65
	jQuery(".pan").on("panstart", function(e) {
66
		panImg = $(".pan img");
67
		panMargin = parseInt(panImg.css("margin-left"), 10);
68
	});
69
	jQuery(".pan").on("pan", function(e) {
70
		console.log("pan");
71
		var delta = panMargin + e.originalEvent.gesture.deltaX;
72
		console.log(delta);
73
		if (delta >= -1750 && delta <= -150) {
74
			panImg.css({"margin-left" : panMargin + e.originalEvent.gesture.deltaX});
75
		}
76
	});
77
    
78
    // tap
79
	new Hammer($(".tap")[0], {
80
		domEvents : true
81
	});
82
	var tapCurrent = 0;
83
	var tapImgs = $(".demo-box.tap img");
84
	$(".tap").on("tap", function(e) {
85
		if (tapImgs[tapCurrent + 1]) {
86
			tapCurrent++;
87
		} else {
88
			tapCurrent = 0;
89
		}
90
		tapImgs.removeClass("active");
91
		tapImgs.eq(tapCurrent).addClass("active");
92
	});
93
	
94
	// swipe
95
	new Hammer($(".swipe")[0], {
96
		domEvents : true
97
	});
98
	var swipeCurrent = 0;
99
	var swipeImgs = $(".demo-box.swipe img");
100
	$(".swipe").on("swipeleft", function(e) {
101
		if (swipeImgs[swipeCurrent + 1]) {
102
			swipeImgs.removeClass("active");
103
			swipeImgs.eq(++swipeCurrent).addClass("active");
104
		}
105
	});
106
	$(".swipe").on("swiperight", function(e) {
107
		if (swipeImgs[swipeCurrent - 1]) {
108
			swipeImgs.removeClass("active");
109
			swipeImgs.eq(--swipeCurrent).addClass("active");
110
		}
111
	});
112
});

+ 0 - 33
display-server/web/biz/js/plugin/panAndSwipe.js

@ -1,33 +0,0 @@
1
require(["domReady!","mobile","jcl","hammer"],function(doc, Mobile, $, Hammer) {
2
	
3
	// 创建一个实例
4
	// 默认指识别水平方向的移动
5
//	var mc = new Hammer(document.getElementById("panElement"));
6
	var mc = new Hammer.Manager(document.getElementById("myElement"));
7
	
8
	var pan = new Hammer.Pan();
9
	var swipe = new Hammer.Swipe();
10
	
11
	mc.add([pan, swipe, new Hammer.Tap()]);
12

13
	// 让手势支持各个方向。
14
	// 这将阻止触控设备的垂直滚动在元素
15
	mc.get('pan').set({ direction: Hammer.DIRECTION_ALL });
16
	mc.get('swipe').set({ direction: Hammer.DIRECTION_ALL });
17
	
18
	// 使互不影响 //recognizeWith requireFailure
19
//	pan.requireFailure(swipe);
20
	swipe.recognizeWith(pan);
21
	
22
	mc.on("panleft panright panup pandown", function(ev){
23
//		$("#panElement").append(ev.type + " gesture detected.");
24
		console.log("pan======"+ev.type);
25
	});
26
	
27
	mc.on("swipeleft swiperight swipeup swipedown", function(ev){
28
//		$("#panElement").append("==="+ev.type + " gesture detected.");
29
		console.log("swipe*********"+ev.type);
30
	});
31

32
	
33
});

+ 3 - 1
display-server/web/res/css/base.css

@ -25,7 +25,7 @@ input,
25 25
textarea { border-radius:0; vertical-align:top;}
26 26
img { vertical-align:top;}
27 27
a { text-decoration:none;}
28

28
.fn-hide {display: none;}
29 29

30 30

31 31
/*motherboard*/
@ -601,6 +601,8 @@ input[type="checkbox"]:checked { opacity:1; }
601 601
.c_tab>.title-tall li { height:0.65rem;}
602 602
.c_tab>.pages .page { position:relative;}
603 603
.c_tab>.pages { -webkit-transition:left 0.4s ease-out; -webkit-transform-style:preserve-3d; position:relative; left:0; overflow:hidden;}
604
.c_tab>.pages-6 { width:600%;}
605
.c_tab>.pages-6 > div { float:left; width:16.6%;}
604 606
.c_tab>.pages-5 { width:500%;}
605 607
.c_tab>.pages-5 > div { float:left; width:20%;}
606 608
.c_tab>.pages-4 { width:400%;}

display-server/web/res/js/base/hammer.js → display-server/web/res/js/base/hammer/hammer.js


+ 2 - 2
display-server/web/res/js/require-config.js

@ -14,7 +14,6 @@ require.config({
14 14
		'zepto' : 'base/zepto',
15 15
		'iScroll' : 'base/iscroll',
16 16
		'iScroll5' : 'base/iscroll5',
17
		'hammer' : 'base/hammer',
18 17
		'o' : 'frame/o',
19 18
		//'oEvent' : 'frame/o-event',
20 19
		'oInput' : 'frame/o-input',
@ -46,7 +45,8 @@ require.config({
46 45
		'wmDialog2' : 'ui/wm-dialog2',
47 46
		'wmDropmenu' : 'ui/wm-dropmenu',
48 47
		'wmRefresh' : 'ui/wm-refresh',
49
		'handlebars' : 'base/handlebars/handlebars'
48
		'handlebars' : 'base/handlebars/handlebars',
49
		'hammer' : 'base/hammer/hammer'
50 50
		
51 51
	},
52 52
	deps: [],

BIN
display-server/web/setup/display-client.apk


+ 1 - 1
display-server/web/template/webapp/PluginIndex.html

@ -59,7 +59,7 @@
59 59
		<div class="pic"><span class="e_ico-nfc"></span></div>
60 60
		<div class="text">NFC</div>
61 61
	</li>
62
	<li action="Gestures">
62
	<li action="Hammer">
63 63
		<div class="pic"><span class="e_ico-nfc"></span></div>
64 64
		<div class="text">手势</div>
65 65
	</li>

+ 0 - 47
display-server/web/template/webapp/plugin/Gestures.html

@ -1,47 +0,0 @@
1
<!DOCTYPE HTML>
2
<html class="s_bs">
3
<head>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
<meta name="viewport"
6
	content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
7
<title>手势</title> {%>template/common/Head.html%}
8
<link href="biz/css/project.css" rel="stylesheet" type="text/css" />
9
<script type="text/javascript" src="biz/js/plugin/gestures.js"></script>
10
</head>
11
<style type="text/css">
12
</style>
13
<body>
14

15
	<div class="c_navBar">
16
		<div class="left">
17
			<div class="back">
18
				<span class="e_ico-back"></span> <span class="text">手势</span>
19
			</div>
20
		</div>
21
	</div>
22

23
	<div class="m_content m_content-nofooter" id="content"
24
		style="position: absolute; top: 0.7rem; bottom: 0rem; left: 0; right: 0;">
25
		<div>
26
			<div class="c_submit" id="consoleMenu">
27
				<ul>
28
					<li><button class="e_button-ok" ontap id="PanAndSwipe">PanAndSwipe实例</button></li>
29
				</ul>
30
				<br>
31
				<ul>
32
					<li><button class="e_button-ok" ontap id="TapAndPress">TapAndPress实例</button></li>
33
				</ul>
34
				<br>
35
				<ul>
36
					<li><button class="e_button-ok" ontap id="PinchAndRotate">PinchAndRotate实例</button></li>
37
				</ul>
38
				<br>
39
				<ul>
40
					<li><button class="e_button-ok" ontap id="Nested">Nested嵌套实例</button></li>
41
				</ul>
42
			</div>
43
		</div>
44
	</div>
45

46
</body>
47
</html>

+ 196 - 0
display-server/web/template/webapp/plugin/Hammer.html

@ -0,0 +1,196 @@
1
<!DOCTYPE HTML>
2
<html class="s_bs">
3
<head>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
6
<title>Hammer</title>
7
{%>template/common/Head.html%}
8
<script type="text/javascript" src="biz/js/plugin/hammer.js"></script>
9
</head>
10
<style type="text/css">
11
.hammer-wrap {
12
	text-align: center;
13
	margin-top: 0.22rem;
14
}
15
.hammer-wrap .hammer-icon {
16
	width: 1rem;
17
}
18
.hammer-wrap h1 {
19
	margin-top: 0.22rem;
20
}
21
.hammer-wrap h2 {
22
	font-weight: normal;
23
    line-height: 1.4;
24
    margin: 0.22rem;
25
}
26

27
.demo-box-wrap {
28
  border: 1px solid #333;
29
  /* font-family: sans-serif; */
30
  background: #333;
31
  text-align: center;
32
  color: white;
33
  width: 302px;
34
  height: 255px;
35
  margin-left: auto;
36
  margin-right: auto;
37
  margin-bottom: 3em;
38
}
39
.demo-box-wrap .demo-box {
40
  width: 300px;
41
  height: 200px;
42
  overflow: hidden;
43
  position: relative;
44
}
45
.demo-box-wrap .demo-box > img {
46
  height: 400px;
47
  width: 1900px;
48
  position: absolute;
49
  margin-left: -950px;
50
  display: none;
51
  pointer-events: none;
52
  margin-top: -220px;
53
  left: 50%;
54
  top: 50%;
55
  max-width: none;
56
}
57
.demo-box-wrap h2 {
58
  pointer-events: none;
59
  color: white;
60
}
61
.demo-box-wrap .demo-box img.active {
62
  display: block;
63
}
64
.demo-overlay {
65
    position: absolute;
66
    top: 0;
67
    left: 0;
68
    right: 0;
69
    bottom: 0;
70
    background: rgba(70, 70, 70, 0.8);
71
    display: none;
72
}
73
.demo-overlay img {
74
    width: 50px;
75
    height: 50px;
76
    position: absolute;
77
    top: 50%;
78
    left: 50%;
79
    margin-left: -25px;
80
    margin-top: -25px;
81
}
82
</style>
83
<body>
84
<div class="c_navBar">
85
	<div class="left">
86
		<div class="back">
87
			<span class="e_ico-back"></span><span class="text">手势</span>
88
		</div>
89
	</div>
90
</div>
91

92
<div class="m_content" id="content">
93
<div>
94
	<div class="hammer-wrap">
95
		<img src="biz/img/plugin/hammer/tap.png" class="hammer-icon">
96
		<h1>Try it!</h1>
97
		<h2>你可以尝试单点图片,实现图片的切换</h2>
98
		<div class="row">
99
			<div class="column large-4 medium-6 small-12">
100
				<div class="demo-box-wrap">
101
					<h2>单点</h2>
102
					<div class="demo-box tap" style="touch-action: pan-y; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
103
						<img class="active" src="biz/img/plugin/hammer/pano-1.jpg">
104
						<img src="biz/img/plugin/hammer/pano-2.jpg">
105
						<img src="biz/img/plugin/hammer/pano-3.jpg">
106
					</div>
107
				</div>
108
			</div>
109
		</div>
110
	</div>
111
	<div class="hammer-wrap">
112
		<img src="biz/img/plugin/hammer/press.png" class="hammer-icon">
113
		<h1>Try it!</h1>
114
		<h2>您可以尝试按住图片,选中图片/取消选中</h2>
115
		<div class="row">
116
			<div class="column large-4 medium-6 small-12">
117
				<div class="demo-box-wrap">
118
				  	<h2>按住</h2>
119
					<div class="demo-box press" style="touch-action: pan-y; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
120
						<img class="active" src="biz/img/plugin/hammer/pano-1.jpg">
121
					 	<div class="demo-overlay">
122
							<img src="biz/img/plugin/hammer/circle-check.svg">
123
						</div>
124
					</div>
125
				</div>
126
			</div>
127
		</div>
128
	</div>
129
	<div class="hammer-wrap">
130
		<img src="biz/img/plugin/hammer/pan.png" class="hammer-icon">
131
		<h1>Try it!</h1>
132
		<h2>您可以尝试平移图片,查看图片更多</h2>
133
		<div class="row">
134
			<div class="column large-4 medium-6 small-12">
135
				<div class="demo-box-wrap">
136
					<h2>平移</h2>
137
					<div class="demo-box pan" style="touch-action: pan-y; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
138
						<img class="active" src="biz/img/plugin/hammer/pano-1.jpg">
139
					</div>
140
				</div>
141
			</div>
142
		</div>
143
	</div>
144
	<div class="hammer-wrap">
145
		<img src="biz/img/plugin/hammer/swipe.png" class="hammer-icon">
146
		<h1>Try it!</h1>
147
		<h2>您可以尝试左右滑动,实现图片的切换</h2>
148
		<div class="row">
149
			<div class="column large-4 medium-6 small-12">
150
				<div class="demo-box-wrap">
151
					<h2>滑动</h2>
152
					<div class="demo-box swipe" style="touch-action: pan-y; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
153
						<img class="active" src="biz/img/plugin/hammer/pano-1.jpg">
154
						<img src="biz/img/plugin/hammer/pano-2.jpg">
155
						<img src="biz/img/plugin/hammer/pano-3.jpg">
156
					</div>
157
				</div>
158
			</div>
159
		</div>
160
	</div>
161
	<div class="hammer-wrap">
162
		<img src="biz/img/plugin/hammer/rotate.png" class="hammer-icon">
163
		<h1>Try it!</h1>
164
		<h2>您可以尝试旋转,实现图片的旋转</h2>
165
		<div class="row">
166
			<div class="column large-4 medium-6 small-12">
167
				<div class="demo-box-wrap">
168
					<h2>旋转</h2>
169
					<div class="demo-box rotate" style="touch-action: none; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
170
						<img class="active" src="biz/img/plugin/hammer/pano-1.jpg" style="transform: rotate(-2deg);">
171
					</div>
172
				</div>
173
			</div>
174
		</div>
175
	</div>
176
	<div class="hammer-wrap">
177
				<img src="biz/img/plugin/hammer/pinch.png" class="hammer-icon">
178
				<h1>Try it!</h1>
179
				<h2>您可以尝试捏放,实现图片的放大/缩小</h2>
180
				<div class="row">
181
					<div class="column large-4 medium-6 small-12">
182
						<div class="demo-box-wrap">
183
							<h2>捏放</h2>
184
							<div class="demo-box pinch" style="touch-action: none; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
185
								<img class="active" src="biz/img/plugin/hammer/pano-1.jpg" style="width: 2269.85px; margin-left: -1134.93px; height: 477.864px; margin-top: -262.825px;">
186
							</div>
187
						</div>
188
					</div>
189
				</div>
190
			</div>
191
</div>
192
</div>
193

194
</div>
195
</body>
196
</html>

+ 0 - 220
display-server/web/template/webapp/plugin/Nested.html

@ -1,220 +0,0 @@
1
<!DOCTYPE HTML>
2
<html class="s_bs">
3
<head>
4
	<meta charset="UTF-8">
5
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
6
    <meta name="msapplication-tap-highlight" content="no"/>
7
    <link rel="stylesheet" href="biz/css/assets/style.css">
8
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9
<title>嵌套pan</title> 
10
{%>template/common/Head.html%}
11
<link href="biz/css/project.css" rel="stylesheet" type="text/css" />
12
<!-- <script type="text/javascript" src="biz/js/plugin/gesture.js"></script> -->
13
<style>
14

15
        .container {
16
            max-width: 900px;
17
            margin: 0 auto;
18
        }
19

20
        .panes.wrapper {
21
            max-height: 400px;
22
            max-width: 800px;
23
            background: #666;
24
            margin: 40px auto;
25
        }
26

27
        .panes {
28
            width: 100%;
29
            height: 100%;
30
            overflow: hidden;
31
            position: relative;
32
        }
33

34
        .pane {
35
            width: 100%;
36
            height: 100%;
37
            position: absolute;
38
            left: 0;
39
            top: 0;
40
            text-align: center;
41
            font: bold 60px/250px 'Open Sans', Helvetica, Arial, sans-serif;
42
            color: #fff;
43
        }
44

45
        .panes.animate > .pane {
46
            transition: all .3s;
47
            -webkit-transition: all .3s;
48
        }
49

50
    </style>
51
</head>
52
<body>
53

54
    <div class="panes wrapper">
55
        <div class="pane bg1">
56
            <div class="panes">
57
                <div class="pane" style="background: rgba(0,0,0,0);">1.1</div>
58
                <div class="pane" style="background: rgba(0,0,0,.2);">1.2</div>
59
                <div class="pane" style="background: rgba(0,0,0,.4);">1.3</div>
60
                <div class="pane" style="background: rgba(0,0,0,.6);">1.4</div>
61
                <div class="pane" style="background: rgba(0,0,0,.8);">1.5</div>
62
            </div>
63
        </div>
64
        <div class="pane bg2">
65
            <div class="panes">
66
                <div class="pane" style="background: rgba(0,0,0,0);">2.1</div>
67
                <div class="pane" style="background: rgba(0,0,0,.2);">2.2</div>
68
                <div class="pane" style="background: rgba(0,0,0,.4);">2.3</div>
69
                <div class="pane" style="background: rgba(0,0,0,.6);">2.4</div>
70
                <div class="pane" style="background: rgba(0,0,0,.8);">2.5</div>
71
            </div>
72
        </div>
73
        <div class="pane bg3">
74
            <div class="panes">
75
                <div class="pane" style="background: rgba(0,0,0,0);">3.1</div>
76
                <div class="pane" style="background: rgba(0,0,0,.2);">3.2</div>
77
                <div class="pane" style="background: rgba(0,0,0,.4);">3.3</div>
78
                <div class="pane" style="background: rgba(0,0,0,.6);">3.4</div>
79
                <div class="pane" style="background: rgba(0,0,0,.8);">3.5</div>
80
            </div>
81
        </div>
82
        <div class="pane bg4">
83
            <div class="panes">
84
                <div class="pane" style="background: rgba(0,0,0,0);">4.1</div>
85
                <div class="pane" style="background: rgba(0,0,0,.2);">4.2</div>
86
                <div class="pane" style="background: rgba(0,0,0,.4);">4.3</div>
87
                <div class="pane" style="background: rgba(0,0,0,.6);">4.4</div>
88
                <div class="pane" style="background: rgba(0,0,0,.8);">4.5</div>
89
            </div>
90
        </div>
91
        <div class="pane bg5">
92
            <div class="panes">
93
                <div class="pane" style="background: rgba(0,0,0,0);">5.1</div>
94
                <div class="pane" style="background: rgba(0,0,0,.2);">5.2</div>
95
                <div class="pane" style="background: rgba(0,0,0,.4);">5.3</div>
96
                <div class="pane" style="background: rgba(0,0,0,.6);">5.4</div>
97
                <div class="pane" style="background: rgba(0,0,0,.8);">5.5</div>
98
            </div>
99
        </div>
100
    </div>
101

102
    <div class="container">
103
        <h1>Nested Pan recognizers</h1>
104

105
        <p>Nested recognizers are possible with some threshold and with use of <code>requireFailure()</code>.</p>
106
    </div>
107

108
    <script src="res/js/base/hammer.js"></script>
109
    <script>
110

111
        var reqAnimationFrame = (function() {
112
            return window[Hammer.prefixed(window, "requestAnimationFrame")] || function(callback) {
113
                setTimeout(callback, 1000 / 60);
114
            }
115
        })();
116

117
        function dirProp(direction, hProp, vProp) {
118
            return (direction & Hammer.DIRECTION_HORIZONTAL) ? hProp : vProp
119
        }
120

121

122
        /**
123
         * Carousel
124
         * @param container
125
         * @param direction
126
         * @constructor
127
         */
128
        function HammerCarousel(container, direction) {
129
            this.container = container;
130
            this.direction = direction;
131

132
            this.panes = Array.prototype.slice.call(this.container.children, 0);
133
            this.containerSize = this.container[dirProp(direction, 'offsetWidth', 'offsetHeight')];
134

135
            this.currentIndex = 0;
136

137
            this.hammer = new Hammer.Manager(this.container);
138
            this.hammer.add(new Hammer.Pan({ direction: this.direction, threshold: 10 }));
139
            this.hammer.on("panstart panmove panend pancancel", Hammer.bindFn(this.onPan, this));
140

141
            this.show(this.currentIndex);
142
        }
143

144

145
        HammerCarousel.prototype = {
146
            /**
147
             * show a pane
148
             * @param {Number} showIndex
149
             * @param {Number} [percent] percentage visible
150
             * @param {Boolean} [animate]
151
             */
152
            show: function(showIndex, percent, animate){
153
                showIndex = Math.max(0, Math.min(showIndex, this.panes.length - 1));
154
                percent = percent || 0;
155

156
                var className = this.container.className;
157
                if(animate) {
158
                    if(className.indexOf('animate') === -1) {
159
                        this.container.className += ' animate';
160
                    }
161
                } else {
162
                    if(className.indexOf('animate') !== -1) {
163
                        this.container.className = className.replace('animate', '').trim();
164
                    }
165
                }
166

167
                var paneIndex, pos, translate;
168
                for (paneIndex = 0; paneIndex < this.panes.length; paneIndex++) {
169
                    pos = (this.containerSize / 100) * (((paneIndex - showIndex) * 100) + percent);
170
                    if(this.direction & Hammer.DIRECTION_HORIZONTAL) {
171
                        translate = 'translate3d(' + pos + 'px, 0, 0)';
172
                    } else {
173
                        translate = 'translate3d(0, ' + pos + 'px, 0)'
174
                    }
175
                     this.panes[paneIndex].style.transform = translate;
176
                     this.panes[paneIndex].style.mozTransform = translate;
177
                     this.panes[paneIndex].style.webkitTransform = translate;
178
                }
179

180
                this.currentIndex = showIndex;
181
            },
182

183
            /**
184
             * handle pan
185
             * @param {Object} ev
186
             */
187
            onPan : function (ev) {
188
                var delta = dirProp(this.direction, ev.deltaX, ev.deltaY);
189
                var percent = (100 / this.containerSize) * delta;
190
                var animate = false;
191

192
                if (ev.type == 'panend' || ev.type == 'pancancel') {
193
                    if (Math.abs(percent) > 20 && ev.type == 'panend') {
194
                        this.currentIndex += (percent < 0) ? 1 : -1;
195
                    }
196
                    percent = 0;
197
                    animate = true;
198
                }
199

200
                this.show(this.currentIndex, percent, animate);
201
            }
202
        };
203

204
        // the horizontal pane scroller
205
        var outer = new HammerCarousel(document.querySelector(".panes.wrapper"), Hammer.DIRECTION_HORIZONTAL);
206

207
        // each pane should contain a vertical pane scroller
208
        Hammer.each(document.querySelectorAll(".pane .panes"), function(container) {
209
            // setup the inner scroller
210
            var inner = new HammerCarousel(container, Hammer.DIRECTION_VERTICAL);
211

212
            // only recognize the inner pan when the outer is failing.
213
            // they both have a threshold of some px
214
            outer.hammer.get('pan').requireFailure(inner.hammer.get('pan'));
215
        });
216

217
    </script>
218

219
</body>
220
</html>

+ 0 - 35
display-server/web/template/webapp/plugin/PanAndSwipe.html

@ -1,35 +0,0 @@
1
<!DOCTYPE HTML>
2
<html class="s_bs">
3
<head>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
<meta name="viewport"
6
	content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
7
<title>手势</title> {%>template/common/Head.html%}
8
<link href="biz/css/project.css" rel="stylesheet" type="text/css" />
9
<script type="text/javascript" src="biz/js/plugin/panAndSwipe.js"></script>
10
</head>
11
<style type="text/css">
12
#myElement {
13
	background: silver;
14
	height: 300px;
15
	text-align: center;
16
	font: 30px/300px Helvetica, Arial, sans-serif;
17
}
18
</style>
19
<body>
20

21
	<div class="c_navBar">
22
		<div class="left">
23
			<div class="back">
24
				<span class="e_ico-back"></span> <span class="text">手势</span>
25
			</div>
26
		</div>
27
	</div>
28

29
	<div class="m_content m_content-nofooter" id="content">
30
		<div class="title">pan举例</div>
31
		<div id="myElement"></div>
32
	</div>
33

34
</body>
35
</html>

+ 0 - 44
display-server/web/template/webapp/plugin/PinchAndRotate.html

@ -1,44 +0,0 @@
1
<!DOCTYPE HTML>
2
<html class="s_bs">
3
<head>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
<meta name="viewport"
6
	content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
7
<title>PinchAndRotate</title> {%>template/common/Head.html%}
8
<link href="biz/css/project.css" rel="stylesheet" type="text/css" />
9
<script src="res/js/base/hammer.js"></script>
10
</head>
11
<style type="text/css">
12
#myElement {
13
  background: silver;
14
  height: 300px;
15
  text-align: center;
16
  font: 30px/300px Helvetica, Arial, sans-serif;
17
}
18
</style>
19
<body>
20

21
	<div id="myElement"></div>
22
<script>
23
	var myElement = document.getElementById('myElement');
24

25
	var mc = new Hammer.Manager(myElement);
26

27
	// create a pinch and rotate recognizer
28
	// these require 2 pointers
29
	var pinch = new Hammer.Pinch();
30
	var rotate = new Hammer.Rotate();
31

32
	// we want to detect both the same time
33
	pinch.recognizeWith(rotate);
34

35
	// add to the Manager
36
	mc.add([pinch, rotate]);
37

38

39
	mc.on("pinch rotate", function(ev) {
40
	    myElement.textContent += ev.type +" ";
41
	});
42
</script>
43
</body>
44
</html>

+ 0 - 45
display-server/web/template/webapp/plugin/TapAndPress.html

@ -1,45 +0,0 @@
1
<!DOCTYPE HTML>
2
<html class="s_bs">
3
<head>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
<meta name="viewport"
6
	content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
7
<title>TapAndPress</title> {%>template/common/Head.html%}
8
<link href="biz/css/project.css" rel="stylesheet" type="text/css" />
9
<script src="res/js/base/hammer.js"></script>
10
</head>
11
<style type="text/css">
12
#myElement {
13
  background: silver;
14
  height: 300px;
15
  text-align: center;
16
  font: 30px/300px Helvetica, Arial, sans-serif;
17
}
18
</style>
19
<body>
20

21
	<div id="myElement"></div>
22
<script>
23
	var myElement = document.getElementById('myElement');
24
	
25
	//We create a manager object, which is the same as Hammer(), but without the presetted recognizers. 
26
	var hammer = new Hammer.Manager(myElement);
27

28
	var singleTap = new Hammer.Tap({event:'singletap'});
29
	var doubleTap = new Hammer.Tap({event:'doubletap', taps:2 });
30
	var tripleTap = new Hammer.Tap({event:'tripletap', taps:3 });
31

32
	hammer.add([tripleTap, doubleTap, singleTap, new Hammer.Press()]);
33
	
34
	// 使互不影响
35
	tripleTap.recognizeWith([doubleTap, singleTap]);
36
	doubleTap.recognizeWith(singleTap);
37
	doubleTap.requireFailure(tripleTap);
38
	singleTap.requireFailure([tripleTap, doubleTap]);
39
	
40
	hammer.on("singletap doubletap tripletap press", function(ev) {
41
	    myElement.textContent += ev.type +" ";
42
	});
43
</script>
44
</body>
45
</html>