{"id":801,"date":"2016-01-12T18:04:58","date_gmt":"2016-01-12T10:04:58","guid":{"rendered":"http:\/\/www.bluesdream.com\/blog\/?p=801"},"modified":"2016-01-12T23:05:45","modified_gmt":"2016-01-12T15:05:45","slug":"simulated-ios-alphabetical-contact-list","status":"publish","type":"post","link":"https:\/\/www.bluesdream.com\/blog\/simulated-ios-alphabetical-contact-list.html","title":{"rendered":"ublue-ContactsList.js\uff08\u6a21\u62dfIOS\u901a\u8baf\u5f55\u5217\u8868\uff09"},"content":{"rendered":"<h3>\u5148\u795d\u5927\u5bb6\u65b0\u5e74\u5feb\u4e50\uff01\u4f5c\u4e3a2016\u5e74\u7684\u5f00\u7bc7\uff0c\u518d\u795d\u5404\u4f4d\u5355\u8eab\u72d7\u65e9\u65e5\u6258\u5355\uff0c\u5df2\u6258\u5355\u7684\u65e9\u65e5\u751f\u7334\u5b50\uff01<\/h3>\n<p>\u524d\u5e74\u63a5\u89e6\u5230\u4e2a\u79fb\u52a8\u7aef\u9879\u76ee\uff0c\u9700\u8981\u628a\u76f8\u5173\u95e8\u5e97\u4fe1\u606f\u4ee5\u7c7b\u4f3cIOS(iPhone)\u8054\u7cfb\u4eba\u5217\u8868\u7684\u5f62\u5f0f\u5448\u73b0\u3002\u5de6\u4fa7\u662f\u57ce\u5e02\u5217\u8868\uff0c\u53f3\u4fa7\u662f\u6ed1\u52a8\u9996\u5b57\u6bcd\u5feb\u901f\u67e5\u627e\u3002<br \/>\n\u5148\u662f\u53bb\u7f51\u4e0a\u641c\u4e86\u4e0b\uff0c\u53d1\u73b0\u76f8\u5173\u8d44\u6599\u5c11\u4e4b\u53c8\u5c11\uff0c\u65e0\u6cd5\u6ee1\u8db3\u9879\u76ee\u9700\u6c42\u3002\u4ee5\u6211\u6027\u683c\uff0c\u6539\u4e00\u4e2a\u5dee\u8ddd\u751a\u8fdc\u7684\u4ee3\u7801\uff0c\u4e0d\u5982\u5728\u6761\u4ef6\u8303\u56f4\u5185\u52a8\u624b\u5199\u4e00\u4e2a\uff0c\u4e5f\u5229\u4e8e\u540e\u671f\u8c03\u8bd5\u3001\u6269\u5c55\u3002<\/p>\n<p>\u53ef\u5728\u9879\u76ee\u7ed3\u675f\u4e4b\u540e\uff0c\u611f\u89c9\u8fd9\u5f62\u5f0f\u7684\u4ea4\u4e92\u6548\u679c\u4eca\u540e\u8bd5\u7528\u8303\u56f4\u548c\u9700\u6c42\u4f1a\u4e0d\u5c11\uff0c\u4fbf\u62ce\u51fa\u6765\u6539\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u63d2\u4ef6\u3002<!--more--><\/p>\n<p>\u9996\u5148\u770b\u4e0b\u9875\u9762\u7ed3\u6784\uff1a<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div class=&quot;contacts&quot;&gt;\r\n\t&lt;div class=&quot;contacts-bd&quot;&gt;\r\n\t\t&lt;div class=&quot;contacts-header&quot;&gt;&lt;\/div&gt;\r\n\t\t&lt;ul class=&quot;contacts-content&quot;&gt;\r\n\t\t\t&lt;li id=&quot;a&quot; class=&quot;contacts-group&quot;&gt;\r\n\t\t\t\t&lt;div class=&quot;contacts-group-hd&quot;&gt;A&lt;\/div&gt;\r\n\t\t\t\t&lt;div class=&quot;contacts-group-bd&quot;&gt;\r\n\t\t\t\t\t&lt;a href=&quot;#&quot;&gt;Aalto&lt;\/a&gt;\r\n\t\t\t\t\t&lt;a href=&quot;#&quot;&gt;Aaron&lt;\/a&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t&lt;\/li&gt;\r\n\t\t\t&lt;li id=&quot;b&quot; class=&quot;contacts-group&quot;&gt;\r\n\t\t\t\t&lt;div class=&quot;contacts-group-hd&quot;&gt;B&lt;\/div&gt;\r\n\t\t\t\t&lt;div class=&quot;contacts-group-bd&quot;&gt;\r\n\t\t\t\t\t&lt;a href=&quot;#&quot;&gt;Baade&lt;\/a&gt;\r\n\t\t\t\t\t&lt;a href=&quot;#&quot;&gt;Baal&lt;\/a&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t&lt;\/li&gt;\r\n\t\t\t...\r\n\t\t\t&lt;li id=&quot;z&quot; class=&quot;contacts-group&quot;&gt;\r\n\t\t\t\t&lt;div class=&quot;contacts-group-hd&quot;&gt;z&lt;\/div&gt;\r\n\t\t\t\t&lt;div class=&quot;contacts-group-bd&quot;&gt;\r\n\t\t\t\t\t&lt;a href=&quot;#&quot;&gt;Zachariah&lt;\/a&gt;\r\n\t\t\t\t\t&lt;a href=&quot;#&quot;&gt;Zachary&lt;\/a&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t&lt;\/li&gt;\r\n\t\t&lt;\/ul&gt;\r\n\t\t&lt;ul class=&quot;contacts-nav&quot; id=&quot;contacts-nav&quot;&gt;\r\n\t\t\t&lt;li alt=&quot;a&quot;&gt;a&lt;\/li&gt;\r\n\t\t\t&lt;li alt=&quot;b&quot;&gt;b&lt;\/li&gt;\r\n\t\t\t...\r\n\t\t\t&lt;li alt=&quot;z&quot;&gt;z&lt;\/li&gt;\r\n\t\t&lt;\/ul&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<h3>\u5728\u6b64\u628a\u6211\u9047\u5230\u7684\u51e0\u4e2a\u4e3b\u8981\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6cd5\u7ed9\u63d0\u53ca\u4e00\u4e0b\uff1a<\/h3>\n<h4>1. \u6d4f\u89c8\u5668\u5f39\u6027\u6eda\u52a8<\/h4>\n<p>\u8fd9\u662f\u5b9e\u9645\u6d4b\u8bd5\u4e2d\u9047\u5230\u7684\u6700\u5927\u9ebb\u70e6\uff0c\u5f39\u6027\u6eda\u52a8\u4e5f\u88ab\u5927\u5bb6\u79f0\u4e4b\u4e3a\u6a61\u76ae\u7b4b\u6548\u679c\/\u62d6\u52a8\u53cd\u5f39\uff0c\u8fd9\u662fIOS\u7684\u4e00\u4e2a\u7279\u5b9a\uff0c\u5e76\u4e0d\u5355\u6307\u5fae\u4fe1\u6d4f\u89c8\u5668\u3002<\/p>\n<blockquote><p>\n  \u5373\uff1a\u6eda\u52a8\u533a\u57df\u5df2\u7ecf\u5230\u8fbe\u9876\u90e8\/\u5e95\u90e8\u65f6\uff0c\u7528\u6237\u7ee7\u7eed\u5411\u4e0a\/\u5411\u4e0b\u6eda\u52a8\uff0c\u4fbf\u4f1a\u89e6\u53d1IOS WebView\u7684\u5f39\u6027\u6eda\u52a8\u3002\n<\/p><\/blockquote>\n<p>\u901a\u5e38\u5728\u505aH5\u9875\u9762\u65f6\uff0c\u4f1a\u6dfb\u52a0\u8fd9\u6837\u4e00\u6bb5\u4ee3\u7801\uff0c\u963b\u6b62\u6d4f\u89c8\u5668\u7684\u9ed8\u8ba4\u884c\u4e3a\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ndocument.addEventListener('touchmove',function(e){\r\n\te.preventDefault();\r\n}, false);\r\n<\/pre>\n<p>\u4f46\u8fd9\u6837\u5199\u5e26\u6765\u7684\u95ee\u9898\u662f\u9875\u9762\u6240\u6709<code>touchmove<\/code>\u4e8b\u4ef6\u88ab\u7981\u6b62\uff0c\u5143\u7d20\u81ea\u8eab\u7684\u6eda\u52a8\u6548\u679c\u4e5f\u4f1a\u53d7\u5230\u5f71\u54cd\u3002\u5bf9\u6b64\uff0c\u5e76\u6ca1\u6709\u4e00\u4e2a\u5f88\u5b8c\u7f8e\u7684\u89e3\u51b3\u529e\u6cd5\uff0c\u4f46\u597d\u5728\u77e5\u9053\u4e86\u89e6\u53d1\u539f\u7406\u3002\u4e8e\u662f\u91c7\u53d6\u4e00\u4e2a\u89c4\u907f\u7684\u65b9\u6cd5<code>\u5f53\u6211\u4eec\u6eda\u52a8\u5230\u5bb9\u5668\u9876\u90e8\u6216\u5e95\u90e8\u65f6\uff0c\u5411\u4e0a\u6216\u5411\u4e0b\u79fb\u52a81\u4e2a\u50cf\u7d20<\/code>\uff0c\u963b\u6b62\u6eda\u52a8\u533a\u57df\u5230\u8fbe\u6700\u9876\u90e8\uff0c\u5c31\u80fd\u6709\u6548\u7684\u7981\u6b62\u6d4f\u89c8\u5668\u9ed8\u8ba4\u4e8b\u4ef6\u540c\u65f6\uff0c\u9632\u6b62\u5f71\u54cd\u5185\u90e8\u6eda\u52a8\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ \u7981\u6b62\u6d4f\u89c8\u5668\u9ed8\u8ba4\u4e8b\u4ef6\u7684\u540c\u65f6\uff0c\u9632\u6b62\u5f71\u54cd\u5185\u90e8\u6eda\u52a8\r\nvar overScroll = function(el) {\r\n\tel.addEventListener('touchstart', function() {\r\n\t\tvar top = el.scrollTop,\r\n\t\t\ttotalScroll = el.scrollHeight,\r\n\t\t\tcurrentScroll = top + el.offsetHeight\r\n\t\t\/\/ \u5f53\u6211\u4eec\u6eda\u52a8\u5230\u5bb9\u5668\u9876\u90e8\u6216\u5e95\u90e8\u65f6\uff0c\u5411\u4e0a\u6216\u5411\u4e0b\u79fb\u52a81\u4e2a\u50cf\u7d20\uff0c\u963b\u6b62\u6574\u4f53\u9875\u9762\u6eda\u52a8\u3002\r\n\t\tif (top === 0) {\r\n\t\t\tel.scrollTop = 1;\r\n\t\t} else if (currentScroll === totalScroll) {\r\n\t\t\tel.scrollTop = top - 1;\r\n\t\t}\r\n\t});\r\n\tel.addEventListener('touchmove', function(e) {\r\n\t\t\/\/ \u5185\u5bb9\u6ea2\u51fa\u65f6\uff0c\u624d\u53ef\u4ee5\u5141\u8bb8\u6eda\u52a8\r\n\t\tif (el.offsetHeight &lt; el.scrollHeight);\r\n\t\t\te._isScroller = true;\r\n\t});\r\n};\r\noverScroll( document.querySelector(opts.contactsContent) );\r\n\/\/ \u7981\u6b62IOS\u9875\u9762\u5f39\u6027\u6eda\u52a8\r\ndocument.addEventListener('touchmove', function(e) {\r\n\tif (!e._isScroller) {\r\n\t\te.preventDefault();\r\n\t};\r\n});\r\n<\/pre>\n<h4>2. touchmove\u65f6\u5224\u65ad\u662f\u5426\u5728\u67d0\u4e2a\u5143\u7d20\u7684\u4f4d\u7f6e\u4e0a<\/h4>\n<p>\u53ef\u4ee5\u4f7f\u7528<code>Document.elementFromPoint()<\/code>\u65b9\u6cd5\uff0c\u6765\u8fd4\u56de\u5f53\u524d\u5750\u6807\u4e0b\u7684\u5143\u7d20\u8282\u70b9\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ndocument.querySelector(opts.groupNav).addEventListener('touchmove', function(e) {\r\n\tvar touch \t= e.changedTouches&#x5B;0],\r\n\t\telem \t= document.elementFromPoint(touch.pageX, touch.pageY);\r\n\tif ( elem && elem.nodeName == &quot;LI&quot; ) {\r\n\t\tcurrentLocation(touch.clientX, touch.clientY);\r\n\t}\r\n});\r\n<\/pre>\n<blockquote><p>\n  API\u6587\u6863\uff1a<a href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/API\/Document\/elementFromPoint\">Document.elementFromPoint() - Web API \u63a5\u53e3 | MDN<\/a>\n<\/p><\/blockquote>\n<h4>3. -webkit-overflow-scrolling:touch \u6240\u5e26\u6765\u7684\u5f71\u54cd<\/h4>\n<p>\u6eda\u52a8\u533a\u57df\u8bbe\u7f6e<code>-webkit-overflow-scrolling:touch<\/code>\u65f6\uff0c\u867d\u7136\u80fd\u4f7f\u6eda\u52a8\u901f\u5ea6\u53d8\u7684\u66f4\u4e3a\u6d41\u7545\u987a\u6ed1\uff0c\u4f46\u7531\u4e8e\u5f39\u6027\u6eda\u52a8\u7684\u5b58\u5728\uff0c\u6211\u505a\u4e86\u4e2a\u6d4b\u8bd5\u3002\u5f53\u6eda\u52a8\u533a\u57df\u56de\u5230\u9876\u90e8\u6216\u5e95\u90e8\u540e\uff0c\u7ee7\u7eed\u5feb\u901f\u62d6\u52a8\u4f1a\u5bfc\u81f4\u90e8\u5206<code>.contacts-group-hd<\/code>\u5143\u7d20\u5b9a\u4f4d\u9519\u8bef\u7684\u60c5\u51b5\u53d1\u751f\u3002\u5177\u4f53\u4ec0\u4e48\u539f\u56e0\uff0c\u76ee\u524d\u8fd8\u4e0d\u6e05\u695a\uff0c\u6240\u4ee5\u6ca1\u6709\u4f7f\u7528\u8be5\u5c5e\u6027\u3002<\/p>\n<p><a class=\"dlBtn\" title=\"Github\" href=\"http:\/\/www.bluesdream.com\/case\/jquery\/ublue-ContactsList\/\" target=\"_blank\">Live Demo<\/a><a class=\"dlBtn\" title=\"Github\" href=\"https:\/\/github.com\/zhonglimh\/ublue-ContactsList\" target=\"_blank\">Github<\/a><\/p>\n<p>\u53c2\u8003\u8d44\u6599\uff1a<br \/>\n<a href=\"https:\/\/github.com\/luster-io\/prevent-overscroll\">prevent-overscroll<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u795d\u5927\u5bb6\u65b0\u5e74\u5feb\u4e50\uff01\u4f5c\u4e3a2016\u5e74\u7684\u5f00\u7bc7\uff0c\u518d\u795d\u5404\u4f4d\u5355\u8eab\u72d7\u65e9\u65e5\u6258\u5355\uff0c\u5df2\u6258\u5355\u7684\u65e9\u65e5\u751f\u7334\u5b50\uff01 \u524d\u5e74\u63a5\u89e6\u5230\u4e2a\u79fb\u52a8\u7aef\u9879\u76ee\uff0c\u9700\u8981\u628a\u76f8\u5173\u95e8\u5e97\u4fe1\u606f\u4ee5\u7c7b\u4f3cIOS(iPhone)\u8054\u7cfb\u4eba\u5217\u8868\u7684\u5f62\u5f0f\u5448\u73b0\u3002\u5de6\u4fa7\u662f\u57ce\u5e02\u5217\u8868\uff0c\u53f3\u4fa7\u662f\u6ed1\u52a8\u9996\u5b57\u6bcd\u5feb\u901f\u67e5\u627e\u3002 \u5148\u662f\u53bb\u7f51\u4e0a\u641c\u4e86\u4e0b\uff0c\u53d1\u73b0\u76f8\u5173\u8d44\u6599\u5c11\u4e4b\u53c8\u5c11\uff0c\u65e0\u6cd5\u6ee1\u8db3\u9879\u76ee\u9700\u6c42\u3002\u4ee5\u6211\u6027\u683c\uff0c\u6539\u4e00\u4e2a\u5dee\u8ddd\u751a\u8fdc\u7684\u4ee3\u7801\uff0c\u4e0d\u5982\u5728\u6761\u4ef6\u8303\u56f4\u5185\u52a8\u624b\u5199\u4e00\u4e2a\uff0c\u4e5f\u5229\u4e8e\u540e\u671f\u8c03\u8bd5\u3001\u6269\u5c55\u3002 \u53ef\u5728\u9879\u76ee\u7ed3\u675f\u4e4b\u540e\uff0c\u611f\u89c9\u8fd9\u5f62\u5f0f\u7684\u4ea4\u4e92\u6548\u679c\u4eca\u540e\u8bd5\u7528\u8303\u56f4\u548c\u9700\u6c42\u4f1a\u4e0d\u5c11\uff0c\u4fbf\u62ce\u51fa\u6765\u6539\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u63d2\u4ef6\u3002<\/p>\n","protected":false},"author":1,"featured_media":802,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[76,138,71,139],"class_list":["post-801","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-front-end","tag-css3","tag-iphone","tag-jquery","tag-ublue-plug-in"],"_links":{"self":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts\/801"}],"collection":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/comments?post=801"}],"version-history":[{"count":0,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts\/801\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/media\/802"}],"wp:attachment":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/media?parent=801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/categories?post=801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/tags?post=801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}