{"id":32932,"date":"2024-11-25T17:15:58","date_gmt":"2024-11-25T09:15:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32932\/"},"modified":"2024-11-25T17:15:58","modified_gmt":"2024-11-25T09:15:58","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%a6%82%e4%bd%95%e6%94%b9%e5%8f%98%e5%85%83%e7%b4%a0%e7%9a%84%e6%a0%b7%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32932\/","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u5982\u4f55\u6539\u53d8\u5143\u7d20\u7684\u6837\u5f0f"},"content":{"rendered":"<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/040\/5e7c1f41b709b135.jpg\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u5982\u4f55\u6539\u53d8\u5143\u7d20\u7684\u6837\u5f0f\u63d2\u56fe\" alt=\"\u5c0f\u7a0b\u5e8f\u5982\u4f55\u6539\u53d8\u5143\u7d20\u7684\u6837\u5f0f\u63d2\u56fe\" \/><\/p>\n<p><strong>1\u3001\u83b7\u53d6\u5143\u7d20\u7684\u6837\u5f0f<\/strong><\/p>\n<p>\u4f7f\u7528wx.createSelectorQuery()\u6765\u83b7\u53d6\u5143\u7d20<\/p>\n<p>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a\u83b7\u53d6\u5143\u7d20\u6837\u5f0f\u7684\u51fd\u6570\u5e94\u8be5\u653e\u5728<strong>onReady\uff1afunction(){}<\/strong>\u8fd9\u4e2a\u91cc\u9762<\/p>\n<pre>let&nbsp;that&nbsp;=&nbsp;this\nconst&nbsp;query&nbsp;=&nbsp;wx.createSelectorQuery()\nquery.select('.detail-card').boundingClientRect()\nquery.select('.detail-header').boundingClientRect()\nquery.exec((res&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;that.setData({\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cardHeight:&nbsp;res[0].height,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;headerHeight:&nbsp;res[1].height\n&nbsp;&nbsp;&nbsp;&nbsp;})\n}))<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2\u3001\u4fee\u6539\u5143\u7d20\u7684\u6837\u5f0f<\/strong><\/p>\n<p>\u8fd9\u91cc\u601d\u8def\u662fWXML\u4e2d\u5143\u7d20\u7684\u6837\u5f0f\u5229\u7528style\u7ed9\u4e00\u4e2a\u53d8\u91cf\uff0c\u901a\u8fc7\u4fee\u6539topList\u8fd9\u4e2a\u6570\u7ec4\u6765\u4fee\u6539top\u5c5e\u6027<\/p>\n<pre>&lt;view&gt;&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>PHP\u4e2d\u6587\u7f51\uff0c\u5927\u91cf\u514d\u8d39\uff0c\u6b22\u8fce\u5b66\u4e60\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u5982\u4f55\u6539\u53d8\u5143\u7d20\u7684\u6837\u5f0f\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>1\u3001\u83b7\u53d6\u5143\u7d20\u7684\u6837\u5f0f \u4f7f\u7528wx.createSelectorQuery()\u6765\u83b7\u53d6\u5143\u7d20 \u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a\u83b7\u53d6\u5143\u7d20\u6837\u5f0f\u7684\u51fd\u6570\u5e94\u8be5\u653e\u5728onReady\uff1afunction(){}\u8fd9\u4e2a\u91cc\u9762 let&nbsp;that&nbsp;=&nbsp;this const&nbsp;query&nbsp;=&nbsp;wx.createSelectorQuery() query.select(&#8216;.detail-card&#8217;).boundingClientRect() query.select(&#8216;.detail-header&#8217;).boundingClientRect() query.exec((res&nbsp;=&amp;gt;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;that.setData({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cardHeight:&nbsp;res[0].height, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;headerHeight:&nbsp;res[1].height &nbsp;&nbsp;&nbsp;&nbsp;}) })) \u767b\u5f55\u540e\u590d\u5236 2\u3001\u4fee\u6539\u5143\u7d20\u7684\u6837\u5f0f \u8fd9\u91cc\u601d\u8def\u662fWXML\u4e2d\u5143\u7d20\u7684\u6837\u5f0f\u5229\u7528style\u7ed9\u4e00\u4e2a\u53d8\u91cf\uff0c\u901a\u8fc7\u4fee\u6539topList\u8fd9\u4e2a\u6570\u7ec4\u6765\u4fee\u6539top\u5c5e\u6027 &lt;view&gt;&lt;\/view&gt; \u767b\u5f55\u540e\u590d\u5236 PHP\u4e2d\u6587\u7f51\uff0c\u5927\u91cf\u514d\u8d39\uff0c\u6b22\u8fce\u5b66\u4e60\uff01 \u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u5982\u4f55\u6539\u53d8\u5143\u7d20\u7684\u6837\u5f0f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-32932","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32932","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=32932"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32932\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}