腾讯 AlloyTeam:超轻量级手势库AlloyFinger
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.****.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
Git:https://github.com/cometwo/AlloyFinger
Demo下载:http://download.****.net/detail/cometwo/9533357
<!DOCTYPE html><html> <head lang="en"> <meta charset="UTF-8"> <title>AlloyFinger</title> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> <style> html, body { margin: 0; padding: 0; border: 0; background-color: #ccc; text-align: center; font: 14px / 1.5 "Helvetica Neue", Helvetica, Arial, "Microsoft Yahei", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif; } .header { background-color: #333; height: 40px; color: white; text-align: left; text-indent: 20px; font-weight: bold; font-size: 20px; line-height: 40px; } .title { height: 30px; color: #333333; font-size: 20px; line-height: 30px; } .example img { width: 160px; } .imgBox { margin-bottom: 10px; border-bottom: 1px solid #333333; } .swipeBox { height: 160px; width: 160px; margin: 0 auto; overflow: hidden; font-size: 0; position: relative; border: 2px solid #ccc; box-sizing: border-box; } .scroll { width: 480px; height: 160px; white-space: nowrap; } .nuclear-nav { position: absolute; bottom: 6px; right: 10px; } .nuclear-nav a { display: inline-block; background-color: white; cursor: pointer; width: 10px; height: 10px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; margin-right: 5px; border: 1px solid #808080; } .nuclear-nav a.active { background-color: #ffd800; } .longTapBox { position: relative; margin: 0 auto; width: 160px; height: 160px; overflow: hidden; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } .longTapBox img { pointer-events: none; } .overlay2, .overlay { background-color: rgba(70, 70, 70, 0.8); position: absolute; top: 0; left: 0; width: 160px; height: 160px; display: none; } .overlay2 img, .overlay img { width: 40px; height: 40px; position: absolute; top: 60px; left: 60px; } .pb6 { padding-bottom: 6px; } .ribbon { top: 3.2em; right: -3.7em; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); color: #fff; display: block; padding: .6em 3.5em; position: fixed; text-align: center; text-decoration: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background-color: green; z-index: 10000; } .btn { letter-spacing: 3px; display: inline-block; color: white; width: 270px; height: 45px; font-size: 24px; line-height: 45px; background-color: green; -moz-border-radius: 2px; -webkit-border-radius: 2px; border-radius: 2px; text-decoration: none; } .footer { height: 120px; } .linkCanvasBox { margin-top: 10px; } .linkCanvasBox .btn { font-size: 16px; } </style> </head> <body> <a href="https://github.com/AlloyTeam/AlloyFinger" class="ribbon">Fork me on Github</a> <div class="header">AlloyFinger</div> <div class="example"> <div class="title">pinch(手势放大缩小)</div> <div class="imgBox"> <img id="pinchImg" src="asset/test.png" /> </div> <div class="title">rotate(手势旋转)</div> <div class="imgBox"> <img id="rotateImg" src="asset/test.png" /> </div> <div class="title">pinch+rotate(手势放大旋转)</div> <div class="imgBox"> <img id="pinchRotateImg" src="asset/test.png" /> </div> <div class="title">pressMove(移动)</div> <div class="imgBox"> <img id="pressMoveImg" src="asset/test.png" /> </div> <div class="title">doubleTap(双击放大,还原)</div> <div class="imgBox"> <img id="doubleTapImg" src="asset/test.png" /> </div> <div class="title">swipe(轮播图)</div> <div class="imgBox pb6"> <div class="swipeBox"> <div class="scroll" id="swipeScroll"> <img src="asset/test.png" /> <img src="asset/test2.png" /> <img src="asset/test3.png" /> </div> <div class="nuclear-nav"> <a data-index="0" class="active"></a> <a data-index="1" class=" "></a> <a data-index="2" class=" "></a> </div> </div> </div> <div class="title">longTap(长按选中)</div> <div class="imgBox pb6"> <div class=" longTapBox" id="longTapBox"> <img id="longTapImg" src="asset/test.png" /> <div class="overlay" id="overlay"> <img src="asset/yes.png" /> </div> </div> </div> <div class="title">tap(点击)</div> <div class="imgBox pb6"> <div class=" longTapBox" id="tapBox"> <img src="asset/test.png" /> <div class="overlay2" id="overlay2"> <img src="asset/yes.png" /> </div> </div> </div> </div> <div class="footer"> <div> <a class="btn" href="http://alloyteam.github.io/AlloyFinger/example/picture/">综合例子→</a></div> <div class="linkCanvasBox"> <a class="btn" href="http://alloyteam.github.io/AlloyFinger/example/canvas/">AlloyPaper+AlloyFinger→</a></div> </div> <script src="asset/transform.js"></script> <script src="alloy_finger.js"></script> <script src="asset/to.js"></script> <script> var pinchImg = document.getElementById("pinchImg"); Transform(pinchImg); var initScale = 1; new AlloyFinger(pinchImg, { multipointStart: function() { initScale = pinchImg.scaleX; }, pinch: function(evt) { pinchImg.scaleX = pinchImg.scaleY = initScale * evt.scale; } }); var rotateImg = document.getElementById("rotateImg"); Transform(rotateImg); new AlloyFinger(rotateImg, { rotate: function(evt) { rotateImg.rotateZ += evt.angle; } }); var pinchRotateImg = document.getElementById("pinchRotateImg"); Transform(pinchRotateImg); new AlloyFinger(pinchRotateImg, { rotate: function(evt) { pinchRotateImg.rotateZ += evt.angle; }, multipointStart: function() { initScale = pinchRotateImg.scaleX; }, pinch: function(evt) { pinchRotateImg.scaleX = pinchRotateImg.scaleY = initScale * evt.scale; } }); var pressMoveImg = document.getElementById("pressMoveImg"); Transform(pressMoveImg); new AlloyFinger(pressMoveImg, { pressMove: function(evt) { pressMoveImg.translateX += evt.deltaX; pressMoveImg.translateY += evt.deltaY; } }); function ease(x) { return Math.sqrt(1 - Math.pow(x - 1, 2)); } var doubleTapImg = document.getElementById("doubleTapImg"); Transform(doubleTapImg); new AlloyFinger(doubleTapImg, { doubleTap: function() { if (doubleTapImg.scaleX === 1) { new To(doubleTapImg, "scaleX", 2, 500, ease); new To(doubleTapImg, "scaleY", 2, 500, ease); } else if (doubleTapImg.scaleX === 2) { new To(doubleTapImg, "scaleX", 1, 500, ease); new To(doubleTapImg, "scaleY", 1, 500, ease); } } }); var swipeScroll = document.getElementById("swipeScroll"), currentIndex = 0; Transform(swipeScroll); function activeNav(index) { var items = document.querySelectorAll(".nuclear-nav a"), i = 0, len = items.length; for (; i < len; i++) { if (i === index) { items[i].classList.add("active"); } else { items[i].classList.remove("active"); } } } new AlloyFinger(swipeScroll, { swipe: function(evt) { if (evt.direction === "Left") { if (currentIndex < 2) { currentIndex++; new To(swipeScroll, "translateX", -160 * currentIndex, 500, ease, function() { activeNav(currentIndex); }); } } else if (evt.direction === "Right") { if (currentIndex > 0) { currentIndex--; new To(swipeScroll, "translateX", -160 * currentIndex, 500, ease, function() { activeNav(currentIndex); }); } } } }); var longTapBox = document.getElementById("longTapBox"); Transform(longTapBox); var overlay = document.getElementById("overlay"); new AlloyFinger(longTapBox, { longTap: function() { toggleDom(overlay); } }); var tapBox = document.getElementById("tapBox"); Transform(tapBox); var overlay2 = document.getElementById("overlay2"); new AlloyFinger(tapBox, { tap: function() { toggleDom(overlay2); }, singleTap: function() { console.log("singleTap") }, doubleTap: function() { console.log("doubleTap") }, pointStart: function() { console.log("pointStart") } }); function toggleDom(dom) { var displayValue = window.getComputedStyle(dom, null)["display"]; if (displayValue === "none") { dom.style.display = "block"; } else { dom.style.display = "none"; } } </script> </body></html>
- 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
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
给我老师的人工智能教程打call!http://blog.****.net/jiangjunshow
Git:https://github.com/cometwo/AlloyFinger
Demo下载:http://download.****.net/detail/cometwo/9533357
<!DOCTYPE html><html> <head lang="en"> <meta charset="UTF-8"> <title>AlloyFinger</title> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> <style> html, body { margin: 0; padding: 0; border: 0; background-color: #ccc; text-align: center; font: 14px / 1.5 "Helvetica Neue", Helvetica, Arial, "Microsoft Yahei", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif; } .header { background-color: #333; height: 40px; color: white; text-align: left; text-indent: 20px; font-weight: bold; font-size: 20px; line-height: 40px; } .title { height: 30px; color: #333333; font-size: 20px; line-height: 30px; } .example img { width: 160px; } .imgBox { margin-bottom: 10px; border-bottom: 1px solid #333333; } .swipeBox { height: 160px; width: 160px; margin: 0 auto; overflow: hidden; font-size: 0; position: relative; border: 2px solid #ccc; box-sizing: border-box; } .scroll { width: 480px; height: 160px; white-space: nowrap; } .nuclear-nav { position: absolute; bottom: 6px; right: 10px; } .nuclear-nav a { display: inline-block; background-color: white; cursor: pointer; width: 10px; height: 10px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; margin-right: 5px; border: 1px solid #808080; } .nuclear-nav a.active { background-color: #ffd800; } .longTapBox { position: relative; margin: 0 auto; width: 160px; height: 160px; overflow: hidden; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } .longTapBox img { pointer-events: none; } .overlay2, .overlay { background-color: rgba(70, 70, 70, 0.8); position: absolute; top: 0; left: 0; width: 160px; height: 160px; display: none; } .overlay2 img, .overlay img { width: 40px; height: 40px; position: absolute; top: 60px; left: 60px; } .pb6 { padding-bottom: 6px; } .ribbon { top: 3.2em; right: -3.7em; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); color: #fff; display: block; padding: .6em 3.5em; position: fixed; text-align: center; text-decoration: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background-color: green; z-index: 10000; } .btn { letter-spacing: 3px; display: inline-block; color: white; width: 270px; height: 45px; font-size: 24px; line-height: 45px; background-color: green; -moz-border-radius: 2px; -webkit-border-radius: 2px; border-radius: 2px; text-decoration: none; } .footer { height: 120px; } .linkCanvasBox { margin-top: 10px; } .linkCanvasBox .btn { font-size: 16px; } </style> </head> <body> <a href="https://github.com/AlloyTeam/AlloyFinger" class="ribbon">Fork me on Github</a> <div class="header">AlloyFinger</div> <div class="example"> <div class="title">pinch(手势放大缩小)</div> <div class="imgBox"> <img id="pinchImg" src="asset/test.png" /> </div> <div class="title">rotate(手势旋转)</div> <div class="imgBox"> <img id="rotateImg" src="asset/test.png" /> </div> <div class="title">pinch+rotate(手势放大旋转)</div> <div class="imgBox"> <img id="pinchRotateImg" src="asset/test.png" /> </div> <div class="title">pressMove(移动)</div> <div class="imgBox"> <img id="pressMoveImg" src="asset/test.png" /> </div> <div class="title">doubleTap(双击放大,还原)</div> <div class="imgBox"> <img id="doubleTapImg" src="asset/test.png" /> </div> <div class="title">swipe(轮播图)</div> <div class="imgBox pb6"> <div class="swipeBox"> <div class="scroll" id="swipeScroll"> <img src="asset/test.png" /> <img src="asset/test2.png" /> <img src="asset/test3.png" /> </div> <div class="nuclear-nav"> <a data-index="0" class="active"></a> <a data-index="1" class=" "></a> <a data-index="2" class=" "></a> </div> </div> </div> <div class="title">longTap(长按选中)</div> <div class="imgBox pb6"> <div class=" longTapBox" id="longTapBox"> <img id="longTapImg" src="asset/test.png" /> <div class="overlay" id="overlay"> <img src="asset/yes.png" /> </div> </div> </div> <div class="title">tap(点击)</div> <div class="imgBox pb6"> <div class=" longTapBox" id="tapBox"> <img src="asset/test.png" /> <div class="overlay2" id="overlay2"> <img src="asset/yes.png" /> </div> </div> </div> </div> <div class="footer"> <div> <a class="btn" href="http://alloyteam.github.io/AlloyFinger/example/picture/">综合例子→</a></div> <div class="linkCanvasBox"> <a class="btn" href="http://alloyteam.github.io/AlloyFinger/example/canvas/">AlloyPaper+AlloyFinger→</a></div> </div> <script src="asset/transform.js"></script> <script src="alloy_finger.js"></script> <script src="asset/to.js"></script> <script> var pinchImg = document.getElementById("pinchImg"); Transform(pinchImg); var initScale = 1; new AlloyFinger(pinchImg, { multipointStart: function() { initScale = pinchImg.scaleX; }, pinch: function(evt) { pinchImg.scaleX = pinchImg.scaleY = initScale * evt.scale; } }); var rotateImg = document.getElementById("rotateImg"); Transform(rotateImg); new AlloyFinger(rotateImg, { rotate: function(evt) { rotateImg.rotateZ += evt.angle; } }); var pinchRotateImg = document.getElementById("pinchRotateImg"); Transform(pinchRotateImg); new AlloyFinger(pinchRotateImg, { rotate: function(evt) { pinchRotateImg.rotateZ += evt.angle; }, multipointStart: function() { initScale = pinchRotateImg.scaleX; }, pinch: function(evt) { pinchRotateImg.scaleX = pinchRotateImg.scaleY = initScale * evt.scale; } }); var pressMoveImg = document.getElementById("pressMoveImg"); Transform(pressMoveImg); new AlloyFinger(pressMoveImg, { pressMove: function(evt) { pressMoveImg.translateX += evt.deltaX; pressMoveImg.translateY += evt.deltaY; } }); function ease(x) { return Math.sqrt(1 - Math.pow(x - 1, 2)); } var doubleTapImg = document.getElementById("doubleTapImg"); Transform(doubleTapImg); new AlloyFinger(doubleTapImg, { doubleTap: function() { if (doubleTapImg.scaleX === 1) { new To(doubleTapImg, "scaleX", 2, 500, ease); new To(doubleTapImg, "scaleY", 2, 500, ease); } else if (doubleTapImg.scaleX === 2) { new To(doubleTapImg, "scaleX", 1, 500, ease); new To(doubleTapImg, "scaleY", 1, 500, ease); } } }); var swipeScroll = document.getElementById("swipeScroll"), currentIndex = 0; Transform(swipeScroll); function activeNav(index) { var items = document.querySelectorAll(".nuclear-nav a"), i = 0, len = items.length; for (; i < len; i++) { if (i === index) { items[i].classList.add("active"); } else { items[i].classList.remove("active"); } } } new AlloyFinger(swipeScroll, { swipe: function(evt) { if (evt.direction === "Left") { if (currentIndex < 2) { currentIndex++; new To(swipeScroll, "translateX", -160 * currentIndex, 500, ease, function() { activeNav(currentIndex); }); } } else if (evt.direction === "Right") { if (currentIndex > 0) { currentIndex--; new To(swipeScroll, "translateX", -160 * currentIndex, 500, ease, function() { activeNav(currentIndex); }); } } } }); var longTapBox = document.getElementById("longTapBox"); Transform(longTapBox); var overlay = document.getElementById("overlay"); new AlloyFinger(longTapBox, { longTap: function() { toggleDom(overlay); } }); var tapBox = document.getElementById("tapBox"); Transform(tapBox); var overlay2 = document.getElementById("overlay2"); new AlloyFinger(tapBox, { tap: function() { toggleDom(overlay2); }, singleTap: function() { console.log("singleTap") }, doubleTap: function() { console.log("doubleTap") }, pointStart: function() { console.log("pointStart") } }); function toggleDom(dom) { var displayValue = window.getComputedStyle(dom, null)["display"]; if (displayValue === "none") { dom.style.display = "block"; } else { dom.style.display = "none"; } } </script> </body></html>
- 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
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369