{"id":32616,"date":"2024-11-25T11:15:55","date_gmt":"2024-11-25T03:15:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32616\/"},"modified":"2024-11-25T11:15:55","modified_gmt":"2024-11-25T03:15:55","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%ae%9e%e7%8e%b0%e5%9b%9e%e5%88%b0%e9%a1%b6%e9%83%a8%e6%95%88%e6%9e%9c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32616\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u56de\u5230\u9876\u90e8\u6548\u679c"},"content":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u70b9\u51fb\u56de\u5230\u9876\u90e8\u7684\u6548\u679c\u5b9e\u73b0\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u5e0c\u671b\u5bf9\u5b66\u4e60\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u7684\u670b\u53cb\u6709\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/040\/5e6845b95b0c6553.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u56de\u5230\u9876\u90e8\u6548\u679c\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u56de\u5230\u9876\u90e8\u6548\u679c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u56de\u5230\u9876\u90e8\u6548\u679c<\/strong><\/p>\n<p>\u8fd9\u91cc\u5c0f\u7a0b\u5e8f\u6709\u4e2a\u7ec4\u4ef6\u662f\u53ef\u4ee5\u5b9e\u73b0\u7684\uff0c\u90a3\u5c31\u662fscroll-view\u7ec4\u4ef6\uff0c\u4ed6\u5177\u6709\u5f88\u591a\u7684\u5c5e\u6027\uff0c\u5176\u4e2d\u6211\u4eec\u8981\u5229\u7528\u5230\u4ee5\u4e0b\u4e24\u4e2a\u5c5e\u6027\u6765\u5904\u7406\uff1a<\/p>\n<blockquote><p>\n  scroll-top&nbsp; Number&nbsp; &nbsp; \u8bbe\u7f6e\u7ad6\u5411\u6eda\u52a8\u6761\u4f4d\u7f6ebindscroll&nbsp; EventHandle&nbsp; &nbsp;\u6eda\u52a8\u65f6\u89e6\u53d1\uff0cevent.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}\n<\/p><\/blockquote>\n<p>\u901a\u8fc7\u6eda\u52a8\u89e6\u53d1\u4e8b\u4ef6\uff0c\u83b7\u53d6\u8ddd\u79bb\u6587\u6863\u9876\u90e8\u7684scrollTop\u503c\uff0c\u5f53\u8fbe\u5230\u4e00\u5b9a\u6761\u4ef6\u3010&gt;300\u3011\u7684\u65f6\u5019\uff0c\u663e\u793agotop\u5c42\uff0c\u9488\u5bf9\u8fd9\u4e2a\u5c42\u5199\u70b9\u51fb\u4e8b\u4ef6\uff0c\u91cd\u65b0\u8bbe\u7f6escroll-top\u503c\uff0c\u5076\u7136\u95f4\u53d1\u73b0\u8bbe\u7f6escroll-top\u7684\u4e00\u4e2abug\uff0c\u5982\u679c\u6211\u4e0b\u4e00\u6b21\u8bbe\u7f6e\u7684\u503c\u548c\u672c\u6b21scroll-top\u503c\u662f\u4e00\u6837\u7684\uff0c\u90a3\u4e48\u6587\u6863\u5e76\u4e0d\u4f1a\u6709\u4efb\u4f55\u52a8\u4f5c\u3002\u56e0\u6b64\u6211\u7684\u505a\u6cd5\u662f\u57280\u548c1\u4e4b\u95f4\u5207\u6362\u8bbe\u7f6e\uff0c\u5177\u4f53\u505a\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>\u63a8\u8350\u5b66\u4e60\uff1a\u6559\u7a0b<\/p>\n<pre>&lt;scroll-view&gt;&nbsp;\n&lt;view&gt;&nbsp;\n123456&nbsp;\n----{{test}}&nbsp;\n&lt;\/view&gt;&nbsp;\n&lt;\/scroll-view&gt;&nbsp;\n&nbsp;&nbsp;&nbsp;\n&lt;view&gt;&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>JS:<\/p>\n<pre>Page({\n&nbsp;&nbsp;data:&nbsp;{\n&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;test:&nbsp;\"\",\n&nbsp;&nbsp;&nbsp;&nbsp;scrollTop:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scroll_top:&nbsp;0,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goTop_show:&nbsp;false\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;},\n&nbsp;&nbsp;scrollTopFun:&nbsp;function&nbsp;(e)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;console.log(e.detail);\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(e.detail.scrollTop&nbsp;&amp;gt;&nbsp;300)&nbsp;{\/\/\u89e6\u53d1gotop\u7684\u663e\u793a\u6761\u4ef6&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setData({\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'scrollTop.goTop_show':&nbsp;true\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(this.data.scrollTop)\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setData({\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'scrollTop.goTop_show':&nbsp;false\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;},\n&nbsp;&nbsp;goTopFun:&nbsp;function&nbsp;(e)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;_top&nbsp;=&nbsp;this.data.scrollTop.scroll_top;\/\/\u53d1\u73b0\u8bbe\u7f6escroll-top\u503c\u4e0d\u80fd\u548c\u4e0a\u4e00\u6b21\u7684\u503c\u4e00\u6837\uff0c\u5426\u5219\u65e0\u6548\uff0c\u6240\u4ee5\u8fd9\u91cc\u52a0\u4e86\u4e2a\u5224\u65ad&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(_top&nbsp;==&nbsp;1)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_top&nbsp;=&nbsp;0;\n&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_top&nbsp;=&nbsp;1;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;this.setData({\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'scrollTop.scroll_top':&nbsp;_top\n&nbsp;&nbsp;&nbsp;&nbsp;});\n&nbsp;&nbsp;&nbsp;&nbsp;console.log(\"----\");\n&nbsp;&nbsp;&nbsp;&nbsp;console.log(this.data.scrollTop)\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6700\u7ec8\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/889\/827\/974\/1583891759473421.gif\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u56de\u5230\u9876\u90e8\u6548\u679c\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u56de\u5230\u9876\u90e8\u6548\u679c\u63d2\u56fe1\" \/><\/p>\n<p>\u66f4\u591a\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u6559\u7a0b\uff0c\u8bf7\u5173\u6ce8\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u56de\u5230\u9876\u90e8\u6548\u679c\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u70b9\u51fb\u56de\u5230\u9876\u90e8\u7684\u6548\u679c\u5b9e\u73b0\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u5e0c\u671b\u5bf9\u5b66\u4e60\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u7684\u670b\u53cb\u6709\u5e2e\u52a9\uff01 \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5b9e\u73b0\u56de\u5230\u9876\u90e8\u6548\u679c \u8fd9\u91cc\u5c0f\u7a0b\u5e8f\u6709\u4e2a\u7ec4\u4ef6\u662f\u53ef\u4ee5\u5b9e\u73b0\u7684\uff0c\u90a3\u5c31\u662fscroll-view\u7ec4\u4ef6\uff0c\u4ed6\u5177\u6709\u5f88\u591a\u7684\u5c5e\u6027\uff0c\u5176\u4e2d\u6211\u4eec\u8981\u5229\u7528\u5230\u4ee5\u4e0b\u4e24\u4e2a\u5c5e\u6027\u6765\u5904\u7406\uff1a scroll-top&nbsp; Number&nbsp; &nbsp; \u8bbe\u7f6e\u7ad6\u5411\u6eda\u52a8\u6761\u4f4d\u7f6ebindscroll&nbsp; EventHandle&nbsp; &nbsp;\u6eda\u52a8\u65f6\u89e6\u53d1\uff0cevent.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY} \u901a\u8fc7\u6eda\u52a8\u89e6\u53d1\u4e8b\u4ef6\uff0c\u83b7\u53d6\u8ddd\u79bb\u6587\u6863\u9876\u90e8\u7684scrollTop\u503c\uff0c\u5f53\u8fbe\u5230\u4e00\u5b9a\u6761\u4ef6\u3010&gt;300\u3011\u7684\u65f6\u5019\uff0c\u663e\u793agotop\u5c42\uff0c\u9488\u5bf9\u8fd9\u4e2a\u5c42\u5199\u70b9\u51fb\u4e8b\u4ef6\uff0c\u91cd\u65b0\u8bbe\u7f6escroll-top\u503c\uff0c\u5076\u7136\u95f4\u53d1\u73b0\u8bbe\u7f6escroll-top\u7684\u4e00\u4e2abug\uff0c\u5982\u679c\u6211\u4e0b\u4e00\u6b21\u8bbe\u7f6e\u7684\u503c\u548c\u672c\u6b21scroll-top\u503c\u662f\u4e00\u6837\u7684\uff0c\u90a3\u4e48\u6587\u6863\u5e76\u4e0d\u4f1a\u6709\u4efb\u4f55\u52a8\u4f5c\u3002\u56e0\u6b64\u6211\u7684\u505a\u6cd5\u662f\u57280\u548c1\u4e4b\u95f4\u5207\u6362\u8bbe\u7f6e\uff0c\u5177\u4f53\u505a\u6cd5\u5982\u4e0b\uff1a \u63a8\u8350\u5b66\u4e60\uff1a\u6559\u7a0b &lt;scroll-view&gt;&nbsp; &lt;view&gt;&nbsp; 123456&nbsp; &#8212;-{{test}}&nbsp; &lt;\/view&gt;&nbsp; &lt;\/scroll-view&gt;&nbsp; &nbsp;&nbsp;&nbsp; &lt;view&gt;&lt;\/view&gt; \u767b\u5f55\u540e\u590d\u5236 JS: Page({ &nbsp;&nbsp;data:&nbsp;{ &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;test:&nbsp;&#8220;&#8221;, &nbsp;&nbsp;&nbsp;&nbsp;scrollTop:&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scroll_top:&nbsp;0, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goTop_show:&nbsp;false &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;}, &nbsp;&nbsp;scrollTopFun:&nbsp;function&nbsp;(e)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;console.log(e.detail); &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(e.detail.scrollTop&nbsp;&amp;gt;&nbsp;300)&nbsp;{\/\/\u89e6\u53d1gotop\u7684\u663e\u793a\u6761\u4ef6&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setData({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8216;scrollTop.goTop_show&#8217;:&nbsp;true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(this.data.scrollTop) &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setData({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8216;scrollTop.goTop_show&#8217;:&nbsp;false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;}, &nbsp;&nbsp;goTopFun:&nbsp;function&nbsp;(e)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;_top&nbsp;=&nbsp;this.data.scrollTop.scroll_top;\/\/\u53d1\u73b0\u8bbe\u7f6escroll-top\u503c\u4e0d\u80fd\u548c\u4e0a\u4e00\u6b21\u7684\u503c\u4e00\u6837\uff0c\u5426\u5219\u65e0\u6548\uff0c\u6240\u4ee5\u8fd9\u91cc\u52a0\u4e86\u4e2a\u5224\u65ad&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(_top&nbsp;==&nbsp;1)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_top&nbsp;=&nbsp;0; &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-32616","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=32616"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32616\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}