{"id":31345,"date":"2024-11-25T17:01:21","date_gmt":"2024-11-25T09:01:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31345\/"},"modified":"2024-11-25T17:01:21","modified_gmt":"2024-11-25T09:01:21","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%bc%80%e5%8f%91%e4%b9%8b%e5%9b%be%e7%89%87%e6%8b%96%e6%8b%bd%e5%8a%9f%e8%83%bd%e7%9a%84%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31345\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u56fe\u7247\u62d6\u62fd\u529f\u80fd\u7684\u5b9e\u73b0"},"content":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u548c\u5927\u5bb6\u5206\u4eab\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u56fe\u7247\u62d6\u62fd\u529f\u80fd\u7684\u5b9e\u73b0\uff0c\u62d6\u62fd\u529f\u80fd\u6211\u4eec\u4f1a\u7ecf\u5e38\u9047\u5230\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002<\/p>\n<p style=\"margin-top:0px;margin-bottom:0px;padding-top:0px;padding-bottom:0px\"><span style=\"font-size:18px;color:#333333\"><span style=\"letter-spacing:.2px\">1.\u7f16\u5199\u9875\u9762\u7ed3\u6784:<\/span><span style=\"letter-spacing:.2px\">moveimg<\/span>.wxml<\/span><\/p>\n<p style=\"margin-top:0px;margin-bottom:0px;padding-top:0px;padding-bottom:0px\"><span style=\"font-size:18px;color:#333333\"><\/span><\/p>\n<pre>&lt;view&gt;&lt;view&gt;&lt;image&gt;&lt;\/image&gt;&lt;\/view&gt;&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size:18px;color:#333333\">2.\u7f16\u5199\u9875\u9762\u6837\u5f0f\uff1amoveimg.wxss<\/span><\/p>\n<pre>.container&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;box-sizing:border-box;\r\n&nbsp;&nbsp;&nbsp;&nbsp;padding:1rem;\r\n}&nbsp;\r\n.cnt{\r\n&nbsp;&nbsp;&nbsp;&nbsp;width:100%;\r\n&nbsp;&nbsp;&nbsp;&nbsp;height:70%;\r\n&nbsp;&nbsp;&nbsp;&nbsp;border:&nbsp;1px&nbsp;solid&nbsp;#ccc;\r\n&nbsp;&nbsp;&nbsp;&nbsp;position:relative;\r\n&nbsp;&nbsp;&nbsp;&nbsp;overflow:&nbsp;hidden;\r\n&nbsp;&nbsp;&nbsp;&nbsp;z-index:9999;\r\n}\r\n.image-style{\r\n\t-webkit-transform:translate(-38px,0px);&nbsp;&nbsp;\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size:18px;color:#333333\">3.<span style=\"letter-spacing:.2px\">\u8bbe\u7f6e\u6570\u636e:moveimg.js<\/span><\/span><\/p>\n<pre>var&nbsp;app&nbsp;=&nbsp;getApp()\r\nPage({\r\n\tdata:&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;\timgwidth:0,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\timgheight:0,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\tanimationData:&nbsp;{},\r\n&nbsp;&nbsp;&nbsp;&nbsp;\tmovex:0,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\tmovey:0,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\tx:0,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\ty:0,\r\n\t},\r\n\tonLoad:&nbsp;function()&nbsp;{\r\n\t\t&nbsp;\/\/&nbsp;\u9875\u9762\u521d\u59cb\u5316&nbsp;options\u4e3a\u9875\u9762\u8df3\u8f6c\u6240\u5e26\u6765\u7684\u53c2\u6570\r\n\t\tvar&nbsp;_this&nbsp;=&nbsp;this;\r\n\t\twx.getSystemInfo({\r\n\t\t\tsuccess:&nbsp;function(res)&nbsp;{\r\n\t\t\t\t_this.setData({\r\n\t\t\t\t\tscreenHeight:&nbsp;res.windowHeight,\r\n\t\t\t\t\tscreenWidth:&nbsp;res.windowWidth,\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t},\r\n\tonReady:function(){\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u9875\u9762\u6e32\u67d3\u5b8c\u6210\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5b9e\u4f8b\u5316\u4e00\u4e2a\u52a8\u753b\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;this.animation&nbsp;=&nbsp;wx.createAnimation({\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\tduration:&nbsp;1000,&nbsp;\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\ttimingFunction:&nbsp;'linear',\/\/\u5747\u5300\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\ttransformOrigin:&nbsp;\"left&nbsp;top&nbsp;0px\",\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;})\r\n\t},\r\n\timageLoad:&nbsp;function(e)&nbsp;{&nbsp;&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;_this=this;&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/1.\u6846\u7684\u5bbd\u9ad8\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;cnt_offetw=_this.data.screenWidth-38,\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\tcnt_offeth=(_this.data.screenHeight-38)*0.7;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/2.\u83b7\u53d6\u56fe\u7247\u771f\u5b9e\u5bbd\u5ea6\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;$width=e.detail.width,&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u83b7\u53d6\u56fe\u7247\u771f\u5b9e\u5bbd\u5ea6&nbsp;&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$height=e.detail.height,&nbsp;&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ratio=$width\/$height;&nbsp;&nbsp;&nbsp;\/\/\u56fe\u7247\u7684\u771f\u5b9e\u5bbd\u9ad8\u6bd4\u4f8b\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\t\/\/3.\u8fdb\u884c\u5224\u65ad:\u5f53\u56fe\u7247\u5c0f\u4e8e\u6846\u65f6\u5019\uff0c\u56fe\u7247\u5927\u5c0f\u7b49\u4e8e\u6846\u5927\u5c0f\uff0c\u5f53\u5927\u4e8e\u6846\u7684\u65f6\u5019\uff0c\u5219\u6210\u6bd4\u4f8b\u5448\u73b0\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\tvar&nbsp;viewWidth=_this.data.screenWidth;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8bbe\u7f6e\u56fe\u7247\u56fa\u5b9a\u5bbd\u5ea6\u503c\uff0c&nbsp;&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var\tviewHeight=parseInt(viewWidth\/ratio);&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8ba1\u7b97\u7684\u9ad8\u5ea6\u503c\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\tif&nbsp;(viewHeight0){\r\n\t\t\t\/\/\u5f80\u53f3\u79fb\u52a8&nbsp;\u5982\u679c\u5f53\u524d\u7684\u503c\u5927\u4e8e\u7b49\u4e8e0\u65f6\u5219\u4e0d\u79fb\u52a8\uff0c\u5426\u5219\u5f53\u524d\u503c\u52a0\u4e0a\u9f20\u6807\u62d6\u62fd\u7684\u8ddd\u79bb\r\n\t\t\tif&nbsp;(endx&nbsp;&amp;gt;=&nbsp;0)&nbsp;{\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;0;\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;endx&nbsp;+&nbsp;DistanceX;\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;}\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;}else{\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\t\/\/\u5f80\u5de6\u79fb\u52a8:x\u62d6\u62fd\u503c\u5927\u4e8e\u7b49\u4e8e\u5f53\u524d\u7684\u503c\uff0c\u8bf4\u660e\u5df2\u7ecf\u5230\u8fb9\u4e0a\u4e86\uff0c\u5c31\u7b49\u4e8e\u62d6\u62fd\u503c\uff0c\u5426\u5219\u5f53\u524d\u7684\u503c\u52a0\u4e0a\u9f20\u6807\u62d6\u62fd\u7684\u8ddd\u79bb\r\n\t\t\tif&nbsp;(w_x&nbsp;&amp;gt;=&nbsp;endx)&nbsp;{\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;-w_x;\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;endx&nbsp;+&nbsp;DistanceX;\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;}\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;}\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(DistanceY&amp;gt;0){\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\t\/\/\u5f80\u4e0b\u79fb\u52a8:\u5982\u679c\u5f53\u524d\u7684\u503c\u5927\u4e8e\u7b49\u4e8e0\u65f6\u5219\u4e0d\u79fb\u52a8\uff0c\u5426\u5219\u5f53\u524d\u503c\u52a0\u4e0a\u9f20\u6807\u62d6\u62fd\u7684\u8ddd\u79bb\r\n\t\t\tif(endy&amp;gt;=0){\r\n\t\t\t\ty&nbsp;=0;\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;}else{\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y&nbsp;=&nbsp;endy&nbsp;+&nbsp;DistanceY;\r\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;}\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;}else{\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\t\/\/\u5f80\u4e0a\u79fb\u52a8:y\u62d6\u62fd\u503c\u5927\u4e8e\u7b49\u4e8e\u5f53\u524d\u7684\u503c\uff0c\u8bf4\u660e\u5df2\u7ecf\u5230\u8fb9\u4e0a\u4e86\uff0c\u5c31\u7b49\u4e8e\u62d6\u62fd\u503c\uff0c\u5426\u5219\u5f53\u524d\u7684\u503c\u52a0\u4e0a\u9f20\u6807\u62d6\u62fd\u7684\u8ddd\u79bb\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\tif(-endy==h_y||-endy&amp;gt;h_y){\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\t\ty=-h_y;\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\t\tconsole.log(\"da0\")\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\t}else{\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\t\ty=endy+DistanceY;\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\t\tconsole.log(\"da&nbsp;1\")\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\t}\r\n\t&nbsp;\t}\r\n&nbsp;&nbsp;&nbsp;\t\tsetTimeout(function()&nbsp;{\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\t_this.animation.translate(x,&nbsp;y).step();\r\n\t\t\t_this.setData({\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\t\tanimationData:&nbsp;this.animation.export()\r\n\t&nbsp;&nbsp;&nbsp;\t\t})\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;}.bind(this),&nbsp;0)\r\n\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;_this.setData({\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\tx:x,\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;\ty:y,\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;})&nbsp;\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;endx=x;endy=y;\/\/\u8bb0\u4f4f\u8fd9\u6b21\u7684\u56fe\u7247\u79fb\u52a8\u7684\u8303\u56f4\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;_this.data.startx=pageX;_this.data.starty=pageY;\/\/&nbsp;\u6bcf\u79fb\u52a8\u4e00\u6b21\u628a\u4e0a\u4e00\u6b21\u7684\u70b9\u4f5c\u4e3a\u539f\u70b9\r\n&nbsp;&nbsp;&nbsp;&nbsp;},\r\n&nbsp;&nbsp;&nbsp;&nbsp;endEvent:function(){\r\n&nbsp;\t\tclearTimeout(function(){\r\n&nbsp;&nbsp;&nbsp;&nbsp;\t\tthis.animation.translate(this.data.x,this.data.y).step();\r\n\t\t\tthis.setData({\r\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\t\tanimationData:&nbsp;this.animation.export()\r\n\t&nbsp;&nbsp;&nbsp;\t\t})\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\t});\r\n&nbsp;&nbsp;&nbsp;&nbsp;}\r\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7531\u4e8e\u4e0a\u6b21\u505a\u7684\u8fd9\u4e2a\u6709\u95ee\u9898\uff0c\u5e76\u6ca1\u6709\u8bb0\u5f55\u4e0a\u4e00\u6b21\u79fb\u52a8\u7684\u6548\u679c\u3002\u6240\u4ee5\u8fd9\u6b21\u6211\u4f7f\u7528\u4e86\u6d2a\u8352\u4e4b\u529b\uff0c\u4fee\u6539\u4e0b\u4ee3\u7801\u3002<\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u56fe\u7247\u62d6\u62fd\u529f\u80fd\u7684\u5b9e\u73b0\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\u6587\u4e3b\u8981\u548c\u5927\u5bb6\u5206\u4eab\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u56fe\u7247\u62d6\u62fd\u529f\u80fd\u7684\u5b9e\u73b0\uff0c\u62d6\u62fd\u529f\u80fd\u6211\u4eec\u4f1a\u7ecf\u5e38\u9047\u5230\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002 1.\u7f16\u5199\u9875\u9762\u7ed3\u6784:moveimg.wxml &lt;view&gt;&lt;view&gt;&lt;image&gt;&lt;\/image&gt;&lt;\/view&gt;&lt;\/view&gt; \u767b\u5f55\u540e\u590d\u5236 2.\u7f16\u5199\u9875\u9762\u6837\u5f0f\uff1amoveimg.wxss .container&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;box-sizing:border-box; &nbsp;&nbsp;&nbsp;&nbsp;padding:1rem; }&nbsp; .cnt{ &nbsp;&nbsp;&nbsp;&nbsp;width:100%; &nbsp;&nbsp;&nbsp;&nbsp;height:70%; &nbsp;&nbsp;&nbsp;&nbsp;border:&nbsp;1px&nbsp;solid&nbsp;#ccc; &nbsp;&nbsp;&nbsp;&nbsp;position:relative; &nbsp;&nbsp;&nbsp;&nbsp;overflow:&nbsp;hidden; &nbsp;&nbsp;&nbsp;&nbsp;z-index:9999; } .image-style{ -webkit-transform:translate(-38px,0px);&nbsp;&nbsp; } \u767b\u5f55\u540e\u590d\u5236 3.\u8bbe\u7f6e\u6570\u636e:moveimg.js var&nbsp;app&nbsp;=&nbsp;getApp() Page({ data:&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp; imgwidth:0, &nbsp;&nbsp;&nbsp;&nbsp; imgheight:0, &nbsp;&nbsp;&nbsp;&nbsp; animationData:&nbsp;{}, &nbsp;&nbsp;&nbsp;&nbsp; movex:0, &nbsp;&nbsp;&nbsp;&nbsp; movey:0, &nbsp;&nbsp;&nbsp;&nbsp; x:0, &nbsp;&nbsp;&nbsp;&nbsp; y:0, }, onLoad:&nbsp;function()&nbsp;{ &nbsp;\/\/&nbsp;\u9875\u9762\u521d\u59cb\u5316&nbsp;options\u4e3a\u9875\u9762\u8df3\u8f6c\u6240\u5e26\u6765\u7684\u53c2\u6570 var&nbsp;_this&nbsp;=&nbsp;this; wx.getSystemInfo({ success:&nbsp;function(res)&nbsp;{ _this.setData({ screenHeight:&nbsp;res.windowHeight, screenWidth:&nbsp;res.windowWidth, }); } }); }, onReady:function(){ &nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u9875\u9762\u6e32\u67d3\u5b8c\u6210 &nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5b9e\u4f8b\u5316\u4e00\u4e2a\u52a8\u753b [&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-31345","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31345","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=31345"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31345\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}