UNPKG

alloytouch

Version:

super tiny size touch and physical motion library for the web

283 lines (254 loc) 8.16 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"> <title>AlloyTouch</title> <style type="text/css"> * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } html { -ms-touch-action: none; } body, ul, li { padding: 0; margin: 0; border: 0; } body { font-size: 12px; font-family: ubuntu, helvetica, arial; overflow: hidden; } #header { position: absolute; z-index: 4; top: 0; left: 0; width: 100%; height: 45px; line-height: 45px; background: #00ABEB; padding: 0; color: #eee; font-size: 20px; text-align: center; font-weight: bold; } #footer { position: absolute; z-index: 2; bottom: 0; left: 0; width: 100%; height: 48px; background: #e2e2e2; padding: 0; } #wrapper { position: absolute; z-index: 1; top: 45px; bottom: 48px; left: 0; width: 100%; background: rgb(233, 230, 230); overflow: hidden; } #scroller { position: absolute; z-index: 2; -webkit-tap-highlight-color: rgba(0,0,0,0); width: 100%; -webkit-transform: translateZ(0); -moz-transform: translateZ(0); -ms-transform: translateZ(0); -o-transform: translateZ(0); transform: translateZ(0); -webkit-touch-callout: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-text-size-adjust: none; -moz-text-size-adjust: none; -ms-text-size-adjust: none; -o-text-size-adjust: none; text-size-adjust: none; top: 0px; } #scroller ul { list-style: none; padding: 0; margin: 0; width: 100%; text-align: left; } #scroller li { padding: 0 10px; height: 40px; line-height: 40px; border-bottom: 1px solid #ccc; border-top: 1px solid #fff; background-color: #fafafa; font-size: 14px; } .pull { width: 100%; position: absolute; text-align: center; top: 10px; z-index: 2; } .pull canvas { width: 31px; } #list li:last-child{ border-bottom:none; } </style> </head> <body> <div> </div> <div id="header">AlloyTouch</div> <div class="pull" id="pull"> <canvas width="62" height="150" id="dripCanvas"></canvas> </div> <div id="wrapper"> <div id="scroller"> <ul id="list"> <li>Hello, AlloyTouch!</li> <li>AlloyFinger - Super Tiny Size Gestures Library</li> <li>Transformjs - Made CSS3 Super Easy</li> <li>AlloyFlow - </li> <li>Nuclear - Some HTML + Scoped CSS + JS </li> <li>AlloyGameEngine</li> <li>Rosin</li> <li>LivePool</li> <li>AlloyStick</li> <li>CodeStar</li> <li>AlloyDesigner</li> <li>JXAnimate</li> <li>Spirit</li> <li>AlloyImage</li> <li>ModJS</li> <li>Pretty row 16</li> <li>stepify</li> <li>AlloyTimer</li> <li>Alloy Desktop</li> <li>JX UI</li> <li>CodeTank</li> <li>iSpriter</li> <li>Rythem</li> <li>Go!Png </li> <li>JX</li> <li>TEditor</li> <li>row 1</li> <li>row 2</li> <li>row 3</li> <li>row 5</li> <li>row 5</li> <li>row 7</li> <li>row 8</li> <li>row 9</li> <li>row 11</li> <li>row 11</li> <li>row 12</li> <li>row 13</li> <li>row 14</li> <li>row 15</li> <li>row 16</li> <li>row 17</li> <li>row 18</li> <li>row 19</li> <li>row 20</li> <li>row 21</li> <li>row 22</li> <li>row 23</li> <li>row 24</li> <li>row 25</li> </ul> </div> </div> <div id="footer"></div> <a href="https://github.com/AlloyTeam/AlloyTouch" target="_blank" style="position: fixed; right: 0; top: 0; z-index: 5; width: 140px; height: 140px;"> <img src="//alloyteam.github.io/github.png" alt=""> </a> <script src="../../transformjs/transform.js"></script> <script src="../../index.js"></script> <script src="asset/drip.js"></script> <script> var target = document.querySelector("#scroller"), list = document.querySelector("#list"), pull = document.querySelector("#pull"), drip = new Drip("#dripCanvas", 30), index = 0, loading = false; //注入transform属性 Transform(pull,true); Transform(target, true); new AlloyTouch({ touch: "#wrapper",//反馈触摸的dom target: target, //运动的对象 property: "translateY", //被滚动的属性 value: 0, min: window.innerHeight - 45 - 48 - 2000, //不必需,滚动属性的最小值 max: 0, //不必需,滚动属性的最大值 touchStart: function () { if (!loading) { drip.show(); } }, change: function (value) { if (value < 40) { pull.translateY = value; } if (!loading) { if (value < 40) { pull.translateY = value; drip.setDistance(0); } else if (value >= 40 && value < 90) { drip.setDistance(2 * (value - 40)); } else { loading = true; mockRequest(this); } } }, touchEnd: function (evt, value) { if (loading) { if (value > 40) { this.to(40); } return false; } if (value > 90) { return false; } } }) function mockRequest(at) { drip.toLoading(); at.to(40); setTimeout(function () { drip.hide(); pull.translateY = 0; var i = 0, len = 3; for (; i < len; i++) { var li = document.createElement("li"); li.innerHTML = "new row " + index++; list.insertBefore(li, list.firstChild); } at.to(at.value); loading = false; at.min -= 40 * 3; }, 2000); } </script> </body> </html>