手机改了分辨率后有误差用公式计算加减还原点击
<p style="margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;">有的人用改分辩率软件,更改了手机的分辩率,为了让所有手机通用一种点击方法,计算偏差,可以用这段代码实现。</p><p style="margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;">两种方法如下:<br style="box-sizing: border-box;"><ignore_js_op></ignore_js_op></p><br style="box-sizing: border-box;">第一种方法:<p></p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">calculateFunction</span>(<span class="hljs-params" style="box-sizing: border-box;">inputValue</span>) </span>{<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">leastSquaresFit</span>(<span class="hljs-params" style="box-sizing: border-box;">x, y</span>) </span>{
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> n = x.length;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> sumX = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> sumY = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> sumXY = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> sumX2 = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">for</span> (<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> i = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>; i < n; i++) {
sumX += x<i>;
sumY += y<i>;
sumXY += x<i> * y<i>;
sumX2 += x<i> * x<i>;
}
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> denominator = (n * sumX2 - sumX * sumX);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (denominator === <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>) {
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>]; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 避免除以零</span>
}
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> a = (n * sumXY - sumX * sumY) / denominator;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> b = (sumY - a * sumX) / n;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> ;
}
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">linearFunction</span>(<span class="hljs-params" style="box-sizing: border-box;">x, a, b</span>) </span>{
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> a * x + b;
}
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">clipValue</span>(<span class="hljs-params" style="box-sizing: border-box;">value, maxValue</span>) </span>{
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">Math</span>.min(value, maxValue);
}
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> x = [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">94</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">155</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">233</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">405</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">591</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">766</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">844</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">930</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">208</span>];
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> y = [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">65</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">157</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">380</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">580</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">810</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">916</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1021</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">140</span>];
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> maxValue = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1080</span>;
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 进行线性拟合,得到线性函数的系数 a 和 b</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> coefficients = leastSquaresFit(x, y);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> a = coefficients[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>];
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> b = coefficients[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>];
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">typeof</span> inputValue === <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'number'</span>) {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 输入为 x 值,计算 y 值</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> predictedY = linearFunction(inputValue, a, b);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 对预测结果进行裁剪,确保不超过 1080</span>
predictedY = clipValue(predictedY, maxValue);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> predictedY;
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">typeof</span> inputValue === <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'number'</span> && inputValue >= <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span> && inputValue <= maxValue) {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 输入为 y 值,计算 x 值</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (a === <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>) {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 当 a 为 0 时,若 b 等于输入的 y 值,x 可以是任意值;否则,无解</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (b === inputValue) {
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">null</span>;
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">NaN</span>;
}
}
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> predictedX = (inputValue - b) / a;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> predictedX;
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">throw</span> <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">Error</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'输入不合法,请输入一个数字且范围在 0 到 '</span> + maxValue + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">' 之间'</span>);
}
}
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 调用函数进行正向计算(根据 x 计算 y)</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> result1 = calculateFunction(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>);
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"当 x = 550 时,计算得到的 y 值为: "</span> + result1);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 调用函数进行反向计算(根据 y 计算 x)</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> result2 = calculateFunction(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>);
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"当 y = 0 时,计算得到的 x 值为: "</span> + result2);
</i></i></i></i></i></i></code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><i><i><i>手机改了分辨率后有误差用公式计算加减,### 函数 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">calculateFunction</code></i></i></i></p><p style="margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><i>这个函数的主要目的是根据输入的数值进行线性拟合计算,可以正向计算(根据 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 值计算 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 值)或反向计算(根据 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 值计算 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 值)。</i></p><h4 id="h4-u5185u90E8u51FDu6570" style="margin-top: 1em; margin-bottom: 1.5em; box-sizing: border-box; position: relative; line-height: 1.75; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 1.1em !important;"><i><a name="内部函数" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>内部函数</i></h4><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i><i><i><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">leastSquaresFit(x, y)</code></span></i></i></i></p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><i>这个函数使用最小二乘法来拟合给定的数据点 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code>,并返回线性函数 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y = ax + b</code> 的系数 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">a</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">b</code>。</i></li><li style="list-style: disc; box-sizing: border-box;"><i><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">n</code> 是数据点的数量。</i></li><li style="list-style: disc; box-sizing: border-box;"><i><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">sumX</code>、<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">sumY</code>、<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">sumXY</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">sumX2</code> 分别是 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 的和、<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 的和、<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 的乘积之和、<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 的平方和。</i></li><li style="list-style: disc; box-sizing: border-box;"><i>通过这些和计算得到 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">a</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">b</code> 的值。</i></li><li style="list-style: disc; box-sizing: border-box;"><i>如果分母为零,为了避免除以零的错误,返回 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);"></code>。</i></li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i><i><i><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">linearFunction(x, a, b)</code></span></i></i></i></p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><i>这是一个简单的线性函数,根据给定的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 值以及拟合得到的系数 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">a</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">b</code>,计算 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 的值。</i></li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i><i><i><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">clipValue(value, maxValue)</code></span></i></i></i></p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><i>这个函数用于确保返回的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 值不超过预先设定的最大值 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">maxValue</code>。</i></li><li style="list-style: disc; box-sizing: border-box;"><i>使用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">Math.min</code> 来比较输入的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">value</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">maxValue</code>,返回较小的那个值。</i></li></ul></li></ol><h4 id="h4-u4E3Bu8981u903Bu8F91" style="margin-top: 1em; margin-bottom: 1.5em; box-sizing: border-box; position: relative; line-height: 1.75; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 1.1em !important;"><i><a name="主要逻辑" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>主要逻辑</i></h4><ul style="margin-bottom: 1.5em; margin-left: 14px; padding-left: 2em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><i>首先,定义了 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 的数据数组,以及 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">maxValue</code> 为 1080。</i></li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><i>然后,使用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">leastSquaresFit</code> 函数计算出拟合直线的系数 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">a</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">b</code>。</i></li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><i><i><i>根据 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">inputValue</code> 的类型和范围进行不同的计算:<ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;">如果 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">inputValue</code> 是一个数字,计算对应的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 值。首先通过 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">linearFunction</code> 计算,然后通过 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">clipValue</code> 确保 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 值不超过 1080。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;">如果 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">inputValue</code> 是一个数字且在 0 到 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">maxValue</code> 之间,尝试反向计算对应的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 值。但如果 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">a</code> 为 0,意味着直线平行于 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 轴,根据 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">b</code> 是否等于 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">inputValue</code> 判断是否有多解或无解。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;">如果输入不符合要求,抛出一个错误信息。</li></ul></i></i></i></li></ul><h4 id="h4-u793Au4F8Bu8C03u7528" style="margin-top: 1em; margin-bottom: 1.5em; box-sizing: border-box; position: relative; line-height: 1.75; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 1.1em !important;"><i><a name="示例调用" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>示例调用</i></h4><ul style="margin-bottom: 1.5em; margin-left: 14px; padding-left: 2em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i><i><i><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var result1 = calculateFunction(100);</code></i></i></i></p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><i>调用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">calculateFunction</code> 函数,传入 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">100</code> 作为 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 值,计算得到对应的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 值,并输出结果。</i></li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><i>注意:示例中的注释有误,应该是 “当 x = 100 时,计算得到的 y 值为: “。</i></li></ul></li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i><i><i><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var result2 = calculateFunction(1);</code></i></i></i></p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><i>调用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">calculateFunction</code> 函数,传入 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">1</code> 作为 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 值,尝试计算对应的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 值。</i></li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><i>同样,注释中的描述有误,应该是 “当 y = 1 时,计算得到的 x 值为: “。</i></li></ul></li></ul><h3 id="h3-u6CE8u610Fu4E8Bu9879" style="margin-top: 1em; margin-bottom: 1.5em; box-sizing: border-box; position: relative; line-height: 1.75; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 1.25em !important;"><i><a name="注意事项" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>注意事项</i></h3><ul style="margin-bottom: 1.5em; margin-left: 14px; padding-left: 2em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>代码中反向计算的部分有一个逻辑错误,<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">else if (typeof inputValue === 'number' && inputValue >= 0 && inputValue <= maxValue)</code> 这部分条件判断似乎与前面的条件重复,只要 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">typeof inputValue === 'number'</code>,就不需要再次判断 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">inputValue</code> 是否在 0 到 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">maxValue</code> 之间。因此这部分代码可以修改为:</i></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><i><i><i><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">else</span> if (inputValue >= <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span> && inputValue <= maxValue) {
</code></i></i></i></pre></li></ul><ul style="margin-bottom: 1.5em; margin-left: 14px; padding-left: 2em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><i>反向计算时,如果 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">a</code> 为 0,则 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">b</code> 的值就是 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 在所有 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 值上的常数值。如果 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">b</code> 等于 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">inputValue</code>,那么理论上对于所有的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code> 值都可以得到这个 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code> 值,因此返回 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">null</code> 表示有多个解。如果 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">b</code> 不等于 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">inputValue</code>,则没有解,返回 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">NaN</code>。</i></li></ul><p style="margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><i>当然看上去很复杂,其实有更简单的方法:</i></p><p style="margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><i>第二种方法:</i></p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><i><i><i><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">adjustPos</span>(<span class="hljs-params" style="box-sizing: border-box;">origPos, origRes, newRes</span>) </span>{
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 计算比例因子</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> scaleFactor = newRes / origRes;
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 调整点击位置</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjustedPos = origPos * scaleFactor;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> adjustedPos;
}
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">adjustPercent</span>(<span class="hljs-params" style="box-sizing: border-box;">origX, origY, origWidth, origHeight, newWidth, newHeight</span>) </span>{
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 调整 x 和 y 坐标</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjX = adjustPos(origX * origWidth, origWidth, newWidth);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjY = adjustPos(origY * origHeight, origHeight, newHeight);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 转换回百分比</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjXPercent = adjX / newWidth;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjYPercent = adjY / newHeight;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> ;
}
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">clickAdjusted</span>(<span class="hljs-params" style="box-sizing: border-box;">origX, origY, origWidth, origHeight, newWidth, newHeight</span>) </span>{
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 计算调整后的百分比坐标</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> = adjustPercent(origX, origY, origWidth, origHeight, newWidth, newHeight);
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"调整后的点击位置为: ("</span> + adjX + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">", "</span> + adjY + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">")"</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 使用 auto.clickPercent 方法进行点击</span>
auto.clickPercent(adjX, adjY);
}
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 示例使用</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> origX = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.6076</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 原始 x 百分比</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> origY = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.1885</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 原始 y 百分比</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> origWidth = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1080</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 原始分辨率宽度</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> origHeight = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1920</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 原始分辨率高度</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> newWidth = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">720</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 新分辨率宽度</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> newHeight = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1280</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 新分辨率高度</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170);">// 直接调用封装的 clickAdjusted 函数</span>
clickAdjusted(origX, origY, origWidth, origHeight, newWidth, newHeight);
</code></i></i></i></pre><p style="margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><i>这段代码的主要作用是根据手机屏幕的不同分辨率,调整点击的位置,以便在不同设备上实现相同的点击效果。以下是对代码的详细解释:</i></p><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i><span style="box-sizing: border-box; font-weight: 700;">调整位置的函数 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">adjustPos</code></span>:</i></p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><i>该函数接受原始位置(<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">origPos</code>)、原始分辨率(<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">origRes</code>)和新分辨率(<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">newRes</code>)作为参数。</i></li><li style="list-style: disc; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>它通过计算比例因子(<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">scaleFactor</code>),然后将原始位置乘以这个因子来得到调整后的点击位置(<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">adjustedPos</code>)。</i></p><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>function adjustPos(origPos, origRes, newRes) {</i></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><i><i><i><code class="hljs kotlin" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> scaleFactor = newRes / origRes;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjustedPos = origPos * scaleFactor;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> adjustedPos;
</code></i></i></i></pre><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>}</i></p></li></ul></li></ol><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i><span style="box-sizing: border-box; font-weight: 700;">调整百分比坐标的函数 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">adjustPercent</code></span>:</i></p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><i>该函数接受原始的百分比坐标(<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">origX</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">origY</code>)、原始分辨率宽度和高度、以及新分辨率的宽度和高度。</i></li><li style="list-style: disc; box-sizing: border-box;"><i>它首先通过 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">adjustPos</code> 函数计算调整后的 x 和 y 坐标。</i></li><li style="list-style: disc; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>然后,它将计算出的坐标转换回绝对百分比,得到实际在新分辨率下的点击位置。</i></p><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>function adjustPercent(origX, origY, origWidth, origHeight, newWidth, newHeight) {</i></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><i><i><i><code class="hljs kotlin" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjX = adjustPos(origX * origWidth, origWidth, newWidth);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjY = adjustPos(origY * origHeight, origHeight, newHeight);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjXPercent = adjX / newWidth;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> adjYPercent = adjY / newHeight;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> ;
</code></i></i></i></pre><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>}</i></p></li></ul></li></ol><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i><span style="box-sizing: border-box; font-weight: 700;">示例使用部分</span>:</i></p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><i>定义原始的百分比坐标和分辨率。</i></li><li style="list-style: disc; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>使用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">adjustPercent</code> 函数计算在新分辨率下的调整坐标,并打印出来。</i></p><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>var origX = 0.6076;<br style="box-sizing: border-box;">var origY = 0.1885;<br style="box-sizing: border-box;">var origWidth = 1080;<br style="box-sizing: border-box;">var origHeight = 1920;<br style="box-sizing: border-box;">var newWidth = 720;<br style="box-sizing: border-box;">var newHeight = 1280;</i></p><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>var = adjustPercent(origX, origY, origWidth, origHeight, newWidth, newHeight);<br style="box-sizing: border-box;">console.log(“调整后的点击位置为: (“ + adjX + “, “ + adjY + “)”);</i></p></li></ul></li></ol><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i><span style="box-sizing: border-box; font-weight: 700;">自动点击方法 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">autoClick</code></span>:</i></p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><i>这个函数是一个占位符,用于执行实际的点击操作。</i></li><li style="list-style: disc; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>当前的实现只是简单输出点击的位置。</i></p><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>function autoClick(xPercent, yPercent) {</i></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><i><i><i><code class="hljs sql" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;">console.<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">log</span>("在屏幕上点击: (" <span class="hljs-operator" style="box-sizing: border-box;">+</span> xPercent <span class="hljs-operator" style="box-sizing: border-box;">+</span> ", " <span class="hljs-operator" style="box-sizing: border-box;">+</span> yPercent <span class="hljs-operator" style="box-sizing: border-box;">+</span> ")");
</code></i></i></i></pre><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>}</i></p></li></ul></li></ol><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i style="color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><span style="box-sizing: border-box; font-weight: 700;">调用自动点击方法</span>:</i><font color="#333333" face="Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif"><i>http://bbs.aiwork24.com/thread-125-1-1.html</i></font></p><ul style="color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>用调整后的 x 和 y 百分比调用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">autoClick</code> 方法,替换为你原来的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">auto.clickPercent</code>。</i></p><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><i>autoClick(adjX, adjY);</i></p></li></ul></li></ol><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><i>这个代码的主要目的在于使得在不同的屏幕分辨率下,点击的行为能够保持一致,从而提高了在不同设备上的用户体验。你提到的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">auto.clickPercent(0.401, 0.2012)</code> 是你自己使用的点击方法,可以直接替换最后一行的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">autoClick</code> 调用</i></p><p></p>
页:
[1]