{"id":1916,"date":"2023-07-02T23:25:48","date_gmt":"2023-07-02T15:25:48","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=1916"},"modified":"2023-07-02T23:25:48","modified_gmt":"2023-07-02T15:25:48","slug":"%e5%ae%9e%e7%8e%b0%e6%8b%96%e6%8b%bd%e7%bb%84%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1916","title":{"rendered":"\u5b9e\u73b0\u62d6\u62fd\u7ec4\u4ef6"},"content":{"rendered":"<p>\u80cc\u666f\uff1a<\/p>\n<p>\u667a\u6167\u517b\u6b96\u79fb\u52a8\u7aef\u8868\u683c\u9875\u6709\u6dfb\u52a0\u529f\u80fd\uff0c\u4f46\u662f\u5f53\u5217\u8868\u5f88\u957f\u65f6\u6309\u94ae\u4f1a\u906e\u6321\u6570\u636e\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\"images\/Pasted%20image%2020230415091447.png\" alt=\"\"><\/p>\n<p>\u6240\u4ee5\u5c31\u9700\u8981\u652f\u6301\u62d6\u52a8\uff0c\u540c\u65f6\u9700\u8981\u4e00\u4e2a\u5438\u8fb9\u7684\u6548\u679c\uff1a<\/p>\n<h2 id=\"\u62d6\u62fd\u539f\u7406\">\u62d6\u62fd\u539f\u7406<\/h2>\n<pre><code>\u4ece\u4e00\u4e2a\u4f4d\u7f6e\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u5b9e\u65f6\u66f4\u6539\u5143\u7d20\u7684\u4f4d\u7f6e \ud83e\udd37\n<\/code><\/pre>\n<h3 id=\"\u79fb\u52a8\">\u79fb\u52a8<\/h3>\n<p><img decoding=\"async\" src=\"images\/Pasted%20image%2020230415094957.png\" alt=\"\"><\/p>\n<pre><code class=\"language-js\">&lt;template&gt;\n\u00a0 &lt;view id=&quot;app&quot;&gt;\n\u00a0 \u00a0 &lt;view class=&quot;move-button&quot; @touchmove=&quot;handleTouchMove&quot; :style=&quot;[style]&quot;&gt;&lt;\/div&gt;\n\u00a0 &lt;\/view&gt;\n&lt;\/template&gt;\n&lt;script&gt;\nexport default {\n\u00a0 name: &#39;App&#39;,\n\u00a0 data() {\n\u00a0 \u00a0 return {\n\u00a0 \u00a0 \u00a0 style: {},\n\u00a0 \u00a0 };\n\u00a0 },\n\u00a0 methods: {\n\u00a0 \u00a0 handleTouchMove(e) {\n\u00a0 \u00a0 \u00a0 console.log(e);\n\u00a0 \u00a0 \u00a0 const { clientX, clientY } = e.touches[0];\n\u00a0 \u00a0 \u00a0 this.style = {\n\u00a0 \u00a0 \u00a0 \u00a0 left: `${clientX}px`,\n\u00a0 \u00a0 \u00a0 \u00a0 top: `${clientY}px`,\n\u00a0 \u00a0 \u00a0 };\n\u00a0 \u00a0 },\n\u00a0 },\n};\n&lt;\/script&gt;\n&lt;style&gt;\n.move-button {\n\u00a0 position: absolute;\n\u00a0 top: 200px;\n\u00a0 right: 0;\n\u00a0 width: 200px;\n\u00a0 height: 200px;\n\u00a0 background-color: blue;\n}\n&lt;\/style&gt;\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u57fa\u672c\u662f\u53ef\u4ee5\u79fb\u52a8\u5143\u7d20\uff0c\u4f46\u662f\u6709\u4e2a\u660e\u663e\u7684\u95ee\u9898\uff0c\u5f53\u5f00\u59cb\u79fb\u52a8\u7684\u77ac\u95f4\u5143\u7d20\u4f1a\u8df3\u52a8\u4e00\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"images\/CPT2304151041-876x613.gif\" alt=\"\"><\/p>\n<p>\u539f\u56e0\u662f\uff1a<strong>\u79fb\u52a8\u65f6\u83b7\u53d6\u7684\u5750\u6807\u8d4b\u503c\u7ed9\u7684\u662f\u5143\u7d20\u7684\u5de6\u4e0a\u89d2\u5750\u6807<\/strong> \u3002<\/p>\n<h4 id=\"\u90a3\u5982\u4f55\u548c\u5904\u7406\uff1f\">\u90a3\u5982\u4f55\u548c\u5904\u7406\uff1f<\/h4>\n<p>\u6211\u4eec\u53ea\u8981\u8bbe\u7f6e\u7684\u4f4d\u7f6e\u4e0d\u662f\u5143\u7d20\u5de6\u4e0a\u89d2\uff0c\u800c\u662f\u8bbe\u7f6e\u5143\u7d20\u7684\u62d6\u52a8\u70b9\u5c31\u884c\u3002\u5b9e\u9645\u662f\u4e0d\u80fd\u8bbe\u7f6e\u5143\u7d20\u5185\u67d0\u4e2a\u70b9\u7684\u4f4d\u7f6e\uff0c\u6211\u4eec\u9700\u8981\u53d8\u901a\u4e0b\u3002\u6211\u4eec\u53d1\u73b0\u62d6\u52a8\u5143\u7d20\u65f6\uff0c\u62d6\u52a8\u70b9\u548c\u5143\u7d20\u7684\u5de6\u4e0a\u89d2\u7684\u4f4d\u7f6e\u4e4b\u95f4\u7684\u5dee\u662f\u4e0d\u53d8\u7684\uff1a<\/p>\n<p><img decoding=\"async\" src=\"images\/Pasted%20image%2020230415105610.png\" alt=\"\"><\/p>\n<p>\u53ea\u8981\u5728\u62d6\u52a8\u5f00\u59cb\u65f6\uff0c\u83b7\u5f97\u5143\u7d20\u5de6\u4e0a\u89d2\u7684\u4f4d\u7f6e\uff08posX,posY\uff09\u4ee5\u53ca\u62d6\u52a8\u70b9\u7684\u8d77\u59cb\u4f4d\u7f6e\uff08startX,startY\uff09\u7136\u540e x\uff0cy \u65b9\u5411\u76f8\u51cf\uff1a<\/p>\n<pre><code class=\"language-js\">const diffX = startX - posX,\n      diffY = startY - posY\n<\/code><\/pre>\n<p>\u83b7\u53d6\u5143\u7d20\u7684\u4fe1\u606f\uff1a<\/p>\n<pre><code class=\"language-js\">getElementInfo(selector){  \n  let view = uni.createSelectorQuery().in(this).select(selector)  \n  \n  return new Promise((resolve, reject)=&gt;{  \n    view.boundingClientRect(data =&gt; {  \n      resolve({  \n        top:data.top,  \n        right:data.right,  \n        bottom:data.bottom,  \n        left:data.left,  \n        width:data.width,  \n        height:data.height,  \n      })  \n    }).exec();  \n  })  \n  \n}\n<\/code><\/pre>\n<pre><code class=\"language-js\">handleTouchStart(e){\n    this.elemInfo = await this.getElementInfo(&#39;.add-img&#39;)  \n    const {clientX,clientY} = e.touches[0]  \n    this.diffX = clientX - this.elemInfo.left  \n    this.diffY = clientY - this.elemInfo.top\n}\n<\/code><\/pre>\n<p>\u4fee\u6539 <code>handleTouchMove<\/code> :<\/p>\n<pre><code class=\"language-js\">    handleTouchMove(e) {\n      console.log(e);\n      const { clientX, clientY } = e.touches[0];\n      this.moveX = clientX - this.diffX\n      this.moveY = clientY - this.diffY\n      this.setButtonPosition()\n    },\n    setButtonPosition(){\n        this.style = {  \n            left:this.moveX + &#39;px&#39;,  \n            top:this.moveY + &#39;px&#39;  \n        }  \n    }\n<\/code><\/pre>\n<h3 id=\"\u5438\u8fb9\">\u5438\u8fb9<\/h3>\n<p>\u539f\u7406\uff1a<strong>\u5f53\u5143\u7d20\u7684\u4e2d\u5fc3\u70b9\u4f4d\u7f6e\u5c0f\u4e8e\u9875\u9762\u5bbd\u5ea6\u4e00\u534a\u65f6\uff0c\u5438\u9644\u5230\u5de6\u8fb9\uff0c\u53cd\u4e4b\u5438\u9644\u5230\u53f3\u8fb9<\/strong> \u3002<\/p>\n<p>\u62d6\u52a8\u505c\u6b62\u540e\uff0c\u6839\u636e\u4e0a\u8ff0\u539f\u7406\u8bbe\u7f6e x \u7684\u5750\u6807\uff1a<\/p>\n<pre><code class=\"language-js\">suctionSide(){  \n  const halfWidth = this.pageWidth\/2  \n  const elemCenterPointX = this.moveX + this.elemInfo.width\/2  \n  if(elemCenterPointX &lt; halfWidth){  \n    \/\/ \u6309\u94ae\u4e2d\u5fc3\u70b9\u4f4d\u7f6e\u5c0f\u4e8e\u4e00\u534a\uff0c\u5438\u9644\u5230\u5de6\u8fb9  \n    this.moveX = 0  \n  }else{  \n    \/\/ \u6309\u94ae\u4e2d\u5fc3\u70b9\u4f4d\u7f6e\u5927\u4e8e\u4e00\u534a\uff0c\u5438\u9644\u5230\u53f3\u8fb9  \n    this.moveX = this.pageWidth - this.elemInfo.width  \n  }  \n  this.setButtonPosition()  \n}\n<\/code><\/pre>\n<p>\u83b7\u53d6\u9875\u9762\u5bbd\u5ea6\uff1a<\/p>\n<pre><code class=\"language-js\">uni.getSystemInfo({  \n  success:res=&gt;{  \n    console.log(res)  \n    this.pageWidth = res.windowWidth  \n  }  \n})\n<\/code><\/pre>\n<p>\u672a\u5b8c\u5f85\u7eed&#8230;<\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<ol>\n<li><a href=\"https:\/\/uniapp.dcloud.net.cn\/api\/ui\/nodes-info.html#createselectorquery\" target=\"_blank\" rel=\"noopener\">uni.createSelectorQuery() | uni-app\u5b98\u7f51<\/a><\/li>\n<li><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f\uff1a \u667a\u6167\u517b\u6b96\u79fb\u52a8\u7aef\u8868\u683c\u9875\u6709\u6dfb\u52a0\u529f\u80fd\uff0c\u4f46\u662f\u5f53\u5217\u8868\u5f88\u957f\u65f6\u6309\u94ae\u4f1a\u906e\u6321\u6570\u636e\uff0c\u5982\u4e0b\u56fe\uff1a \u6240\u4ee5\u5c31\u9700\u8981\u652f\u6301\u62d6\u52a8&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-1916","post","type-post","status-publish","format-standard","hentry","category-frontend"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1916"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1916\/revisions"}],"predecessor-version":[{"id":1917,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1916\/revisions\/1917"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}