{"id":309,"date":"2013-08-29T13:01:46","date_gmt":"2013-08-29T05:01:46","guid":{"rendered":"https:\/\/yanjingang.com\/blog\/?p=309"},"modified":"2016-01-26T13:02:14","modified_gmt":"2016-01-26T05:02:14","slug":"%e8%a7%a3%e5%86%b3iscroll%e6%a8%aa%e5%90%91%e6%bb%9a%e5%8a%a8%e5%8c%ba%e5%9f%9f%e6%97%a0%e6%b3%95%e6%8b%89%e5%8a%a8%e9%a1%b5%e9%9d%a2%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/yanjingang.com\/blog\/?p=309","title":{"rendered":"\u89e3\u51b3iScroll\u6a2a\u5411\u6eda\u52a8\u533a\u57df\u65e0\u6cd5\u62c9\u52a8\u9875\u9762\u7684\u95ee\u9898"},"content":{"rendered":"<div>\u8fd1\u671f\u9879\u76ee\u4e2d\u4f7f\u7528iScroll\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u5728\u8bbe\u5b9awrapper\u4e3a\u6a2a\u5411\u6eda\u52a8\u65f6\uff0c\u5982\u679c\u4f60\u624b\u6307\u653e\u5728\u8be5\u533a\u57df\uff0c\u5c06\u65e0\u6cd5\u62c9\u52a8\u9875\u9762\uff0c\u4e5f\u5c31\u662f\u8bf4\u8be5\u533a\u57df\u53d6\u6d88\u4e86\u9ed8\u8ba4\u4e8b\u4ef6\u3002\u8fd9\u4e2a\u4f53\u9a8c\u662f\u5b9e\u5728\u662f\u65e0\u6cd5\u63a5\u53d7\uff0c\u7279\u522b\u662f\u9875\u9762\u4e2d\u6709\u591a\u4e2a\u6a2a\u5411\u6eda\u52a8\u533a\u57df\u65f6\uff0c\u5f88\u5bb9\u6613\u89e6\u78b0\u5230\u8fd9\u79cd\u533a\u57df\uff0c\u8fd9\u65f6\u7528\u6237\u5c06\u89c9\u5f97\u9875\u9762\u5f88\u5361\u3002<\/div>\n<p>Google\u641c\u4e86\u4e00\u4e0b\uff0c\u770b\u6765\u5f88\u591a\u4eba\u90fd\u4e3a\u8fd9\u4e2a\u95ee\u9898\u800c\u70e6\u607c\u3002\u6709\u9ad8\u4eba\u7ed9\u51fa\u4e86\u89e3\u51b3\u65b9\u6848\uff0c\u5728<a href=\"http:\/\/stackoverflow.com\/questions\/7800261\/iscroll-with-native-scrolling-on-one-axis\" target=\"_blank\">\u8fd9\u91cc<\/a>\u53ef\u4ee5\u627e\u5230\u3002<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>myScroll\u00a0=\u00a0new\u00a0iScroll(&#8216;scrollpanel&#8217;,\u00a0{<br \/>\n\/\/ other options go here&#8230;<br \/>\nvScroll:\u00a0false,<br \/>\nonBeforeScrollStart:\u00a0function\u00a0(\u00a0e\u00a0)\u00a0{<br \/>\nif\u00a0(\u00a0this.absDistX\u00a0&gt;\u00a0(this.absDistY\u00a0+\u00a05\u00a0)\u00a0)\u00a0{<br \/>\n\/\/ user is scrolling the x axis, so prevent the browsers&#8217; native scrolling<br \/>\ne.preventDefault();<br \/>\n}<br \/>\n}<br \/>\n});<\/p>\n<p>\u91cd\u5199onBeforeScrollStart\u4e8b\u4ef6\uff0c\u5224\u65adtouch\u7684\u6ed1\u52a8\u8ddd\u79bb\uff0c\u53ea\u5728\u6a2a\u5411\u6ed1\u52a8\u8ddd\u79bb\u5927\u4e8e\u7ad6\u5411\u6ed1\u52a8\u8ddd\u79bb\u65f6\uff08\u4e5f\u5c31\u662f\u5de6\u53f3\u6ed1\u52a8\u65f6\uff09\u624d\u53d6\u6d88\u9ed8\u8ba4\u4e8b\u4ef6\uff0c\u8fd9\u6837\u5c31\u4e0d\u5f71\u54cd\u9875\u9762\u6eda\u52a8\u4e86\u3002\u770biScroll\u6e90\u7801\uff0conBeforeScrollStart: function (e) { e.preventDefault(); }, \u5b83\u9ed8\u8ba4\u662f\u76f4\u63a5\u53d6\u6d88\u9ed8\u8ba4\u4e8b\u4ef6\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\u7684\u65f6\u5019\u611f\u89c9\u5c31\u4e0d\u9519\u4e86\u3002\u4f46\u662f\u4e0d\u8981\u9ad8\u5174\u7684\u592a\u65e9\u3002<\/p>\n<p>\u4e0a\u4e0b\u6ed1\u52a8\u6a2a\u5411\u6eda\u52a8\u533a\u57df\uff0c\u9875\u9762\u786e\u5b9e\u53ef\u4ee5\u6eda\u52a8\u4e86\uff0c\u4f46\u5728\u591a\u4f53\u9a8c\u4e86\u51e0\u6b21\u9875\u9762\u4e4b\u540e\uff0c\u53c8\u51fa\u73b0\u4e86\u4e00\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u5148\u5de6\u53f3\u6ed1\u52a8\u8be5\u533a\u57df\uff0c\u6eda\u52a8\u505c\u6b62\u540e\u518d\u6309\u4f4f\u8be5\u533a\u57df\u60f3\u6eda\u52a8\u9875\u9762\uff0c\u4f60\u4f1a\u53d1\u73b0\u5b83\u8fd8\u662f\u4e0d\u80fd\u6eda\u52a8\u9875\u9762\uff0c\u8fd9\u65f6\u4f60\u518d\u70b9\u51fb\u4e00\u6b21\u8be5\u533a\u57df\uff0c\u8fd9\u65f6\u53ef\u4ee5\u4e86\u3002\u8fd9\u76f8\u5bf9\u4e8e\u4f60\u9700\u8981\u89e6\u64782\u6b21\u624d\u80fd\u6eda\u52a8\u9875\u9762\uff0c \u8fd9\u6837\u7684\u884c\u4e3a\u8fd8\u662f\u8ba9\u4eba\u65e0\u6cd5\u63a5\u53d7\u3002<\/p>\n<p>\u7ecf\u8fc7\u591a\u7ffb\u6d4b\u8bd5\uff0c\u6211\u628a\u95ee\u9898\u9501\u5b9a\u5230absDistX\/Y\u4e0a\u3002\u6700\u540e\u53d1\u73b0\uff0c\u5728\u5de6\u53f3\u6ed1\u52a8\u4e4b\u540eabsDistX\/Y\u7684\u503c\u4e0d\u4f1a\u91cd\u7f6e\uff0c\u7b2c\u4e8c\u6b21\u6ed1\u52a8\u8be5\u533a\u57df\u65f6\u6267\u884conBeforeScrollStart\u4e8b\u4ef6\uff0c\u91cc\u9762absDistX\/Y\u503c\u662f\u4e0a\u4e00\u6b21\u7684\u503c\uff0c\u6240\u4ee5\u7a0b\u5e8f\u8fd8\u662f\u963b\u6b62\u4e86\u9875\u9762\u6eda\u52a8\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>myScroll\u00a0=\u00a0new\u00a0iScroll(&#8216;scrollpanel&#8217;,\u00a0{<br \/>\n\/\/ other options go here&#8230;<br \/>\nhScroll:\u00a0true,<br \/>\nonBeforeScrollStart:\u00a0function\u00a0(\u00a0e\u00a0)\u00a0{<br \/>\nif\u00a0(\u00a0this.absDistX\u00a0&gt;\u00a0(this.absDistY\u00a0+\u00a05\u00a0)\u00a0)\u00a0{<br \/>\n\/\/ user is scrolling the x axis, so prevent the browsers&#8217; native scrolling<br \/>\ne.preventDefault();<br \/>\n}<br \/>\n},<br \/>\n\/\/\u89e3\u51b3\u7b2c\u4e00\u6b21\u65e0\u6cd5\u6ed1\u52a8\u7684\u95ee\u9898<br \/>\nonTouchEnd:\u00a0function\u00a0()\u00a0{<br \/>\nvar\u00a0self\u00a0=\u00a0this;<br \/>\nif\u00a0(self.touchEndTimeId)\u00a0{<br \/>\nclearTimeout(self.touchEndTimeId);<br \/>\n}<\/p>\n<p>self.touchEndTimeId\u00a0=\u00a0setTimeout(function\u00a0()\u00a0{<br \/>\nself.absDistX\u00a0=\u00a00;<br \/>\nself.absDistY\u00a0=\u00a00;<br \/>\n},\u00a0600);<br \/>\n}<br \/>\n});<\/p>\n<p>\u5728onTouchEnd\u91cc\u9762\u505a\u5904\u7406\uff0c\u6bcf\u6b21\u6ed1\u52a8\u4e4b\u540e\u90fd\u91cd\u7f6eabsDistX\/Y\u7684\u503c\u3002\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528setTimeout\uff1f\u5176\u5b9e\u662f\u4e3a\u4e86\u9632\u6b62\u8bef\u5224\u65ad\uff0c\u592a\u654f\u611f\u4e5f\u4e0d\u597d\uff0c\u6709\u65f6\u5019\u4f60\u53ea\u662f\u60f3\u5de6\u53f3\u6ed1\u52a8\u867d\u7136\u6ed1\u52a8\u7684\u89d2\u5ea6\u6709\u70b9\u671d\u4e0a\u6216\u671d\u4e0b\u3002<\/p>\n<p>Ok\uff0c\u73b0\u5728\u7ec8\u4e8e\u723d\u4e86\uff0c\u60f3\u600e\u4e48\u6ed1\u90fd\u884c\u3002<a href=\"http:\/\/oklai.name\/m\/response\/index.html\" target=\"_blank\">\u4f53\u9a8c\u4e00\u4e0b\uff01<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd1\u671f\u9879\u76ee\u4e2d\u4f7f\u7528iScroll\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u5728\u8bbe\u5b9awrapper\u4e3a\u6a2a\u5411\u6eda\u52a8\u65f6\uff0c\u5982\u679c\u4f60\u624b\u6307\u653e\u5728\u8be5\u533a\u57df\uff0c\u5c06\u65e0\u6cd5\u62c9\u52a8\u9875 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[26],"tags":[214,215],"_links":{"self":[{"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/309"}],"collection":[{"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309"}],"version-history":[{"count":0,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/309\/revisions"}],"wp:attachment":[{"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yanjingang.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}