{"id":3202,"date":"2021-04-09T15:52:08","date_gmt":"2021-04-09T07:52:08","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=3202"},"modified":"2026-08-18T12:35:34","modified_gmt":"2026-08-18T04:35:34","slug":"%e5%89%8d%e7%ab%af%e5%bf%85%e5%a4%87%e8%87%aa%e5%ae%9a%e4%b9%89%e6%bb%9a%e5%8a%a8%e5%ba%93-iscroll","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3202","title":{"rendered":"\u524d\u7aef\u5fc5\u5907\u81ea\u5b9a\u4e49\u6eda\u52a8\u5e93\u2014\u2014iScroll"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u4e0d\u5c11\u573a\u666f\u7528 body \u6eda\u52a8\u4e0d\u65b9\u4fbf\uff0c\u53ea\u80fd\u5c40\u90e8\u6eda\u52a8\uff1aWindows \u6d4f\u89c8\u5668\u6eda\u52a8\u6761\u96be\u770b\uff0ciOS \u9ed8\u8ba4\u6ca1\u6709\u60ef\u6027\u548c\u5f39\u6027\uff0c\u52a0\u4e0a <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">-webkit-overflow-scrolling: touch<\/code> \u53c8\u4e00\u5806\u517c\u5bb9\u95ee\u9898\uff0c\u4e2a\u6027\u5316\u7684\u52a0\u8f7d\u3001\u5237\u65b0\u3001\u8d34\u5408\u6eda\u52a8\u66f4\u96be\u505a\u3002<strong style=\"color: #4870ac;\">iScroll<\/strong> \u7528 CSS3 transform \u6a21\u62df\u63a5\u8fd1\u539f\u751f\u7684\u60ef\u6027\/\u5f39\u6027\u6eda\u52a8\uff0c\u8fd8\u80fd\u81ea\u5b9a\u4e49\u6eda\u52a8\u6761\u3001\u6eda\u5230\u6307\u5b9a\u5143\u7d20\u3001\u4e0b\u62c9\u5237\u65b0\u548c\u4e0a\u62c9\u52a0\u8f7d\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4f5c\u8005\u662f\u56fd\u9645\u53cb\u4eba\uff0cGitHub <a href=\"https:\/\/github.com\/cubiq\">\u5728\u6b64<\/a>\u3002\u9879\u76ee\u51e0\u4e4e\u4e0d\u518d\u7ef4\u62a4\uff0c\u4e2d\u6587\u6587\u6863\u4e5f\u5c11\uff0c\u4f46\u4e0d\u59a8\u788d\u7ee7\u7eed\u7528\u3002\u914d\u7f6e\u53ef\u53c2\u8003 http:\/\/wiki.jikexueyuan.com\/project\/iscroll-5\/\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u57fa\u672c\u4f7f\u7528<\/h2>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">\u5b89\u88c5<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">npm install iscroll\n\nyarn add iscroll<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">\u5f15\u7528<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">import IScroll from 'iscroll\/build\/iscroll'; \/\/ \u666e\u901a\u7248\n\nimport IScroll from 'iscroll\/build\/iscroll-probe'; \/\/ \u590d\u6742\u7248\n\nimport IScroll from 'iscroll\/build\/iscroll-infinite';<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6709\u666e\u901a\u7248\u3001\u590d\u6742\u7248\uff08probe\uff0c\u53ef\u5b9e\u65f6\u542c\u4f4d\u7f6e\uff09\u3001\u65e0\u9650\u6eda\u52a8\u7248\u3002\u5e38\u7528\u590d\u6742\u7248\uff1b\u4e0d\u9700\u8981\u5b9e\u65f6\u76d1\u542c\u7528\u666e\u901a\u7248\u5373\u53ef\u3002<\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">\u521d\u59cb\u5316\uff08\u4ee5 Vue \u4e3a\u4f8b\uff09<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;template&gt;\n  &lt;div class=\"wrap\"&gt;\n    &lt;div class=\"scroll-area\"&gt;\n      &lt;div v-for=\"n in 50\" class=\"item\"&gt;{{ n }}&lt;\/div&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n&lt;script&gt;\n  import IScroll from 'iscroll\/build\/iscroll-probe';\n  \n  export default {\n    data() {\n      scroll: null,\n    },\n    mounted() {\n      \/\/ \u63d0\u793a\uff0c\u56e0\u4e3atransform\u662f\u5bf9dom\u64cd\u4f5c\uff0c\u6240\u4ee5\u9700\u8981\u5728\u8fd9\u4e2a\u751f\u547d\u5468\u671f\u64cd\u4f5c\n      this.scroll = new IScroll('.wrap', {\n        mouseWheel: true, \/\/ \u5141\u8bb8\u9f20\u6807\u6eda\u8f6e\n      });\n      \/\/ \u7b2c\u4e00\u4e2a\u53c2\u6570\u662fdom\u9009\u62e9\u5668\uff0c\u5efa\u8bae\u4f7f\u7528\u552f\u4e00\u6027\u7684id\uff0c\u8fd9\u91cc\u4ee5class\u4e3a\u4f8b\n      \/\/ \u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u53c2\u6570\u5bf9\u8c61\uff0c\u662fiscroll\u7684\u4e00\u4e9b\u914d\u7f6e\n      \/\/ \u53c2\u6570\u914d\u7f6e\u53ef\u4ee5\u53c2\u8003 http:\/\/wiki.jikexueyuan.com\/project\/iscroll-5\/\n    }\n  }\n&lt;\/script&gt;\n&lt;style&gt;\n  .wrap{\n    height: 400px;\n    overflow: hidden;\n    \/* \u7ed9\u6eda\u52a8\u533a\u57df\u56fa\u5b9a\u53ef\u6eda\u52a8\u9ad8\u5ea6\uff0c\u5e76\u4e14\u8d85\u51fa\u9690\u85cf *\/\n  }\n&lt;\/style&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">transform \u64cd\u4f5c DOM\uff0c\u6240\u4ee5\u5728 mounted \u91cc new IScroll\u3002\u7b2c\u4e00\u4e2a\u53c2\u6570\u5efa\u8bae\u7528\u552f\u4e00 id\u3002\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/16ad3de2282bdf6b.gif\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3204\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/16ad3de2282bdf6b.gif\" alt=\"16ad3de2282bdf6b\" width=\"298\" height=\"424\" \/><\/a><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u5237\u65b0<\/h2>\n<p style=\"margin: 1em 0px;\">\u5185\u5bb9\u82e5\u5f02\u6b65\u63d2\u5165 DOM\uff0c\u4e0d refresh \u6eda\u52a8\u4f1a\u4e0d\u51c6\u3002\u5f02\u6b65\u5b8c\u6210\u6216\u9996\u6b21 touchstart \u65f6\u8c03\u7528 refresh\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;template&gt;\n  &lt;div ref=\"scroll\" class=\"wrap\"&gt;\n    &lt;div class=\"scroll-area\"&gt;\n      &lt;div v-for=\"n in 50\" class=\"item\"&gt;{{ n }}&lt;\/div&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n&lt;script&gt;\n  import IScroll from 'iscroll\/build\/iscroll-probe';\n  \n  export default {\n    data() {\n      scroll: null,\n    },\n    mounted() {\n      const el = this.$refs.scroll;\n      this.scroll = new IScroll('.wrap', {\n        ...\n      });\n      \/\/ \u2460 \u5f02\u6b65\u6570\u636e\u5237\u65b0\n      getData().then(_=&gt;{\n        this.scroll.refresh();\n      })\n      \/\/ \u2461 \u9996\u6b21\u6ed1\u52a8\u65f6\u5237\u65b0\n      el.addEventListener('touchstart', _=&gt;this.scroll.refresh());\n    }\n  }\n&lt;\/script&gt;<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e09\u3001\u76d1\u542c\u4f4d\u7f6e<\/h2>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">this.scroll = new IScroll('.wrap', {\n  probeType: 3, \/\/ \u6eda\u52a8\u76d1\u542c\u7ea7\u522b  \u67093\u6863\uff0c3\u662f\u50cf\u7d20\u7ea7\u76d1\u542c\n});\n\/\/ \u7528iscroll\u5b9e\u4f8b\u6ce8\u518cscroll\u4e8b\u4ef6\nthis.scroll.on('scroll', e =&gt; {\n  \/\/ \u6b64\u5904\u4e0d\u7528\u7bad\u5934\u51fd\u6570\u53ef\u4ee5\u7528this.x\u548cthis.y\u8bbf\u95ee\u5b9e\u65f6\u4f4d\u7f6e\uff0c\u7528\u4e86\u7bad\u5934\u51fd\u6570\u9700\u8981\u4ece\u5b9e\u4f8b\u4e0a\u8bbf\u95ee\n  \/\/ this.scroll.x\n  \/\/ this.scroll.y\n})<\/code><\/pre>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/16ad3f8327f81fb1.gif\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3205\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/16ad3f8327f81fb1.gif\" alt=\"16ad3f8327f81fb1\" width=\"232\" height=\"460\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u53d6\u503c\u6b63\u8d1f\u5bf9\u5e94 transform \u65b9\u5411\uff0c\u5148\u786e\u8ba4\u5750\u6807\u3002\u7bad\u5934\u51fd\u6570\u8981\u4ece\u5b9e\u4f8b\u8bfb x\/y\uff0c\u4e0d\u7528\u7bad\u5934\u53ef\u7528 this.x \/ this.y\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u56db\u3001\u6eda\u52a8\u5230\u6307\u5b9a\u5143\u7d20\uff08snap\uff09<\/h2>\n<p style=\"margin: 1em 0px;\">\u8d34\u5408\u529f\u80fd\uff1asnap \u4e3a true \u65f6\u6309\u53ef\u89c6\u533a\u57df\u5206\u9875\uff1b\u4e3a\u9009\u62e9\u5668\u65f6\u6bcf\u4e2a\u5339\u914d\u5143\u7d20\u4e00\u9875\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">this.scroll = new IScroll('.wrap', {\n  snap: '.item',\n});\n\/\/ \u5f53\u8bbe\u7f6esnap\u5c5e\u6027\u4e3atrue\u65f6\uff0ciscroll\u4f1a\u628a\u5bb9\u5668\u53ef\u89c6\u533a\u57df\u5206\u5272\u4e3a\u4e00\u4e2apage\n\/\/ \u5f53\u8bbe\u7f6esnap\u5c5e\u6027\u4e3a\u5143\u7d20\u9009\u62e9\u5668\u65f6\uff0ciscroll\u4f1a\u628a\u5bf9\u5e94\u7684\u5143\u7d20\u8bbe\u7f6e\u4e3a\u4e00\u4e2apage\n\/\/ \u8fd9\u91cc\u6211\u4eec\u8bbe\u7f6e\u4e3a'.item'<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u518d\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">goToPage<\/code>\uff0c\u53c2\u6570\u662f x \u7d22\u5f15\u3001y \u7d22\u5f15\u3001\u52a8\u753b\u65f6\u95f4\uff08\u4ece 0 \u8d77\uff09\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">this.scroll.goToPage(0, 30, 1000);\n\n\/\/ \u53c2\u6570\u5206\u522b\u4e3ax, y, \u52a8\u753b\u65f6\u95f4,\n\n\/\/ \u6ce8\u610fx,y\u662f\u4f20\u5165\u7d22\u5f15\uff0c\u7b2c\u4e00\u4e2a\u662f0\uff0c\u7c7b\u63a8<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u4e5f\u53ef\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">prev<\/code> \/ <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">next<\/code>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">this.scroll.prev();\n\nthis.scroll.next();<\/code><\/pre>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/16ad41861ceda9d4.gif\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3206\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/16ad41861ceda9d4.gif\" alt=\"16ad41861ceda9d4\" width=\"232\" height=\"506\" \/><\/a><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e94\u3001\u914d\u7f6e\u6eda\u52a8\u6761<\/h2>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">this.scroll = new IScroll('.wrap', {\n  scrollbars: true, \/\/ \u5f00\u542f\u6eda\u52a8\u6761\n  shrinkScrollbars: 'scale', \/\/ \u8d85\u51fa\u6eda\u52a8\u65f6\uff0c\u7f29\u653e\u6eda\u52a8\u6761\n});\n\/* \u56e0\u4e3aiscroll\u7684\u6eda\u52a8\u6761\u662f\u5b9a\u4f4d\u5b9e\u73b0\uff0c\u6240\u4ee5\u5bb9\u5668\u9700\u8981\u52a0\u4e00\u4e2a\u76f8\u5bf9\u5b9a\u4f4d *\/\n.wrap{\n  position: relative;\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6eda\u52a8\u6761\u662f\u5b9a\u4f4d\u5b9e\u73b0\uff0c\u5bb9\u5668\u8981 position: relative\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/16ad434618148e69.gif\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3207\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/16ad434618148e69.gif\" alt=\"16ad434618148e69\" width=\"232\" height=\"506\" \/><\/a><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u516d\u3001\u70b9\u51fb\u4e8b\u4ef6<\/h2>\n<p style=\"margin: 1em 0px;\">\u9ed8\u8ba4\u7981\u7528 click\uff0c\u9700\u8981\u5c31\u6253\u5f00\uff1b\u4e5f\u5185\u7f6e tap\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">this.scroll = new IScroll('.wrap', {\n\n  click: true,\n\n});<\/code><\/pre>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">this.scroll = new IScroll('.wrap', {\n  tap: true,\n});\n&lt;template&gt;\n  &lt;div ref=\"scroll\" class=\"wrap\"&gt;\n    &lt;div class=\"scroll-area\"&gt;\n      &lt;div v-for=\"n in 50\" class=\"item\" @tap=\"onTap\"&gt;{{ n }}&lt;\/div&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e03\u3001Sticky \u5438\u9876<\/h2>\n<p style=\"margin: 1em 0px;\">\u539f\u751f\u6eda\u52a8\u53ef\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">position: sticky<\/code> + <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">top: 0<\/code> \u5438\u9876\uff08\u6a2a\u5411\u540c\u7406\uff09\u3002\u517c\u5bb9\u6027\u4e00\u822c\uff0c<a href=\"https:\/\/caniuse.com\/#search=sticky\">\u6233\u8fd9\u91cc<\/a>\u3002iScroll \u7528 transform \u4e14 overflow:hidden\uff0cCSS sticky \u65e0\u6548\uff0c\u5230\u8fbe\u5438\u9876\u4f4d\u7f6e\u65f6\u5bf9\u5b50\u5143\u7d20\u505a\u53cd\u5411 transform\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e0b\u9762\u8fd9\u6bb5\u662f\u5bf9 iScroll \u7c7b\u7684\u6269\u5c55\uff0c\u8bf7\u5bf9\u7167\u6ce8\u91ca\u770b\uff1a<\/strong><\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\/\/ \u8fd9\u6bb5\u4ee3\u7801\u53ef\u4ee5\u7406\u89e3\u4e3a\u662f\u5bf9iscroll\u7c7b\u7684\u6269\u5c55\n\/\/ \u8fd9\u91cc\u7684\u53c2\u6570\u4e3aiscroll\u7c7b\nexport const extendSticky = (iScroll) =&gt; {\n  let m = Math;\n  \/\/ \u8fd9\u91cc\u662f\u4e3a\u4e86\u517c\u5bb9\u6027\u914d\u7f6e\u7684\u6d4f\u89c8\u5668css\u524d\u7f00\uff0c\u7f51\u7edc\u4e0a\u6709\u5f88\u591a\u5199\u6cd5\u5462\n  let vendor = (\/webkit\/i).test(navigator.appVersion) ? 'webkit' :\n      (\/firefox\/i).test(navigator.userAgent) ? 'Moz' :\n        'opera' in window ? 'O' : '',\n    has3d = 'WebKitCSSMatrix' in window &amp;&amp; 'm11' in new WebKitCSSMatrix(),\n    trnOpen = 'translate' + (has3d ? '3d(' : '('),\n    trnClose = has3d ? ',0)' : ')';\n  \n  \/**\n   * \u8fd9\u91cc\u5f00\u59cb\u62d3\u5c55iscroll\u7c7b\n   * @param selector \u9700\u8981sticky\u7684\u5bf9\u8c61\u96c6\u5408\uff0c\u5305\u542b\u5143\u7d20\u548csticky\u7684\u4f4d\u7f6e\n   * @return { iScrollStickyHeaders }\n   *\/\n   \/\/ \u5728iscroll\u539f\u578b\u4e0a\u6dfb\u52a0 enableStickyHeaders \u65b9\u6cd5\n  iScroll.prototype.enableStickyHeaders = function (selector) {\n    return new iScrollStickyHeaders(this, selector); \/\/ \u62d3\u5c55\u65b9\u6cd5\u91c7\u7528\u65b0\u7684\u7c7b\u5e76\u4f20\u53c2\n  };\n  \/\/ \u53c2\u6570\uff0ciscroll\u5b9e\u4f8b\uff0c\u9700\u8981sticky\u7684\u5143\u7d20\u96c6\u5408\n  let iScrollStickyHeaders = function (iscroll, selector) {\n    if (!iscroll.options.useTransform) {\n      return;\n    }\n    this.iscroll = iscroll;\n    this.selector = selector;\n    this.initialize(); \/\/ \u521d\u59cb\u5316\n  };\n  iScrollStickyHeaders.prototype = {\n    headers: [], \/\/ \u5b58\u50a8\u9700\u8981sticky\u7684\u5bf9\u8c61\u96c6\u5408\n    initialize() {\n      let that = this;\n      this._augment();\n      this.iscroll.on('refresh', function() {\n        that._refresh() \/\/ \u6bcf\u6b21iscroll\u5237\u65b0\uff0csticky\u65b9\u6cd5\u4e5f\u5237\u65b0\n      });\n      this.iscroll.refresh()\n    },\n    _refresh() { \/\/ \u521d\u59cb\u5316\u6216\u8005\u5237\u65b0\n      let elms = this.selector;\n      this.headers = [ \/\/ \u6df1\u62f7\u8d1d\u5bf9\u8c61\u96c6\u5408\n        ...elms,\n      ]\n      \/\/ \u6b64\u5904\u5bf9\u8c61\u96c6\u5408\u7684\u683c\u5f0f\u4e3a { el: \u5143\u7d20, top: \u9700\u8981sticky\u7684\u4f4d\u7f6e }\n      \/\/ \u6b64\u5904\u53ef\u4ee5\u6839\u636e\u4e60\u60ef\u548c\u559c\u6b22\u81ea\u884c\u5b9a\u4e49\u683c\u5f0f\u548c\u903b\u8f91\u4ee3\u7801\n      this._translate(0\uff0c 0); \/\/ \u521d\u59cb\u5316\n    },\n    _augment() { \/\/ \u521d\u59cb\u5316\u51fd\u6570\n      let that = this;\n      this.iscroll.on('scroll', function() {\n        that._translate(this.x, this.y) \/\/ iscroll\u6eda\u52a8\u65f6\uff0c\u89e6\u53d1\u4e3b\u51fd\u6570\n      });\n      this.iscroll.on('beforeScrollStart', function() {\n        that._translate(this.x, this.y) \/\/ iscroll\u5373\u5c06\u6eda\u52a8\u65f6\uff0c\u89e6\u53d1\u4e3b\u51fd\u6570\n      });\n      this.iscroll.on('scrollStart', function() {\n        that._translate(this.x, this.y) \/\/ iscroll\u5f00\u59cb\u6eda\u52a8\u65f6\uff0c\u89e6\u53d1\u4e3b\u51fd\u6570\n      });\n    },\n    _translate(x, y) { \/\/ \u4e3b\u51fd\u6570\uff0c\u5230\u8fbesticky\u4f4d\u7f6e\u540e\uff0c\u53cd\u5411transform\n      let absY = m.abs(y); \/\/ \u83b7\u53d6y\u8f74\u6eda\u52a8\u7684\u7edd\u5bf9\u503c\n      this.headers.forEach((stickyObj) =&gt; { \/\/ \u904d\u5386sticky\u5bf9\u8c61\n        let translateY = 0; \/\/ sticky\u7684\u53cd\u5411transform\u9ed8\u8ba4\u4e3a0\n        let yy = m.abs(absY - stickyObj.el.offsetTop); \/\/ \u8ba1\u7b97iscroll\u7684y\u8f74\u6eda\u52a8\u503c-\u5f53\u524d\u5143\u7d20\u8ddd\u79bb\u7236\u7ea7\u7684\u503c\n        \/\/ stickyObj.el.offsetTop\u4e3a\u56fa\u5b9a\u503c\n        \/\/ yy\u5373\u4e3a\u5f53\u524d\u5143\u7d20\u8ddd\u79bb\u5bb9\u5668\u9876\u90e8\u7684\u4f4d\u7f6e\n        \/\/ absY &lt; stickyObj.el.offsetTop\u8bf4\u660e\u8be5\u5143\u7d20\u8fd8\u6ca1\u5230\u8fbe\u9876\u90e8\n        \/\/ yy &lt;= stickyObj.top \u5224\u65ad\u5143\u7d20\u662f\u5426\u5230\u8fbe\u9700\u8981sticky\u7684\u4f4d\u7f6e\n        \/\/ \u2460 \u5f53\u5143\u7d20\u8fd8\u6ca1\u5230\u8fbe\u5bb9\u5668\u9876\u90e8\u65f6\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u518d\u5224\u65ad\u662f\u5426\u5230\u8fbe\u6307\u5b9asticky\u4f4d\u7f6e\n        \/\/ \u2461 \u5982\u679c\u6ca1\u5230\u8fbe\u6307\u5b9asticky\uff0c\u4f9d\u7136\u4e3a0\n        \/\/ \u2462 \u5982\u679c\u8fbe\u5230\u6307\u5b9asticky\u4f4d\u7f6e\uff0c\u90a3\u4e48\u5c31\u8ba1\u7b97\u8d85\u8fc7sticky\u4f4d\u7f6e\u540e\uff0c\u9700\u8981\u53cd\u5411transform\u7684\u8ddd\u79bb\n        \/\/ \u2463 \u8fd9\u91cc\u9ed8\u8ba4\u6307\u5b9a\u4f4d\u7f6e\u662f\u5c0f\u4e8e\u5143\u7d20\u521d\u59cb\u4f4d\u7f6e\u7684\uff0c\u6307\u5b9a\u4f4d\u7f6e\u5927\u4e8e\u521d\u59cb\u4f4d\u7f6e\u7684\uff0c\u6211\u60f3\u4f1a\u5f88\u5947\u8469\u5427\u3002\n        if (absY - stickyObj.el.offsetTop &gt; 0 || yy &lt;= stickyObj.top) {\n          \/\/ \u8fd9\u4e2a\u516c\u5f0f\u9700\u8981\u53cd\u590d\u7406\u89e3\u4e00\u4e0b\n          \/\/ \u5f53\u5bb9\u5668\u5f80\u4e0a\u6eda\u52a8\u65f6\uff0c\u5bb9\u5668\u7684transform\u662f\u8d1f\u503c\uff0c\u6240\u4ee5\u6211\u4eec\u53cd\u5411\u662f\u6b63\u503c\n          \/\/ \u5bb9\u5668\u5411\u4e0a\u6eda\u52a8\u503cabsY\u4e0d\u65ad\u53d8\u5927\uff0c\u6211\u4eecsticky\u5c31\u4e0d\u65ad\u5411\u4e0btransform\n          \/\/ stickyObj.el.offsetTop - stickyObj.top \u5373\u4e3a\u5bb9\u5668\u6eda\u52a8\u591a\u5c11\u8303\u56f4\u624d\u4f1a\u8ba9\u5143\u7d20\u5230\u8fbe\u6307\u5b9asticky\u4f4d\u7f6e\n          \/\/ \u8ba1\u7b97iscroll\u5bb9\u5668\u7684\u6eda\u52a8\u503c - (\u521d\u59cb\u4f4d\u7f6e - \u6307\u5b9a\u4f4d\u7f6e)\n          \/\/ \u5f53\u6eda\u52a8\u503c\u7b49\u4e8e\u521d\u59cb\u4f4d\u7f6e\u548c\u6307\u5b9a\u4f4d\u7f6e\u4e4b\u5dee\u65f6\uff0c\u521a\u597d\u7b49\u4e8e0\n          \/\/ \u968f\u7740\u6eda\u52a8\u503c\u8d8a\u6765\u8d8a\u5927\uff0c\u8d85\u8fc70\u7684\u90e8\u5206\uff0c\u5373\u4e3a\u9700\u8981\u53cd\u5411transform\u7684\u503c\n          translateY = absY - (stickyObj.el.offsetTop - stickyObj.top);\n        } else {\n          translateY = 0;\n        }\n        \/\/ \u6700\u540e\u62fc\u63a5\u6d4f\u89c8\u5668\u524d\u7f00\uff0c\u5b8c\u6210css\u8d4b\u503c\n        stickyObj.el.style[vendor + 'Transform'] = trnOpen + ('0, ' + translateY + 'px') + trnClose;\n      });\n    },\n  };\n};\nexport default extendSticky;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u793a\u610f\u56fe\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/20210409154749.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-3208\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/20210409154749.png\" alt=\"20210409154749\" width=\"1061\" height=\"662\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u5de5\u5177\u6587\u4ef6 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">iscroll-sticky.js<\/code> \u5199\u597d\u540e\u8fd9\u6837\u7528\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;template&gt;\n  &lt;div ref=\"scroll\" class=\"wrap\"&gt;\n    &lt;div class=\"scroll-area\"&gt;\n      &lt;div v-for=\"n in 20\" class=\"item\"&gt;{{ n }}&lt;\/div&gt;\n      &lt;div ref=\"sticky\" class=\"sticky\" :top=\"20\"&gt;21&lt;\/div&gt;\n      &lt;div v-for=\"n in 20\" class=\"item\"&gt;{{ n+20 }}&lt;\/div&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n&lt;script&gt;\n  import IScroll from 'iscroll\/build\/iscroll-probe';\n  import enableSticky from 'path\/to\/iscroll-sticky.js';\n  enableSticky(IScroll); \/\/ \u8fd9\u4e00\u6b65\u662f\u5c06sticky\u65b9\u6cd5\u6302\u8f7d\u5230iscroll\u539f\u578b\u4e0a\n  \n  export default {\n    data() {\n      scroll: null,\n    },\n    mounted() {\n      const el = this.$refs.scroll;\n      this.scroll = new IScroll('.wrap', {\n        ...\n      });\n      const stickyEl = this.$refs.sticky;\n      \/\/ \u5141\u8bb8\u5143\u7d20\u5bf9\u8c61\u96c6\u5408sticky\n      this.scroll.enableStickyHeaders([\n        {\n          el: stickyEl,\n          top: stickyEl.getAttribute('top') \/\/ \u6b64\u5904\u6211\u628atop\u503c\u914d\u7f6e\u5728\u4e86\u539f\u751fprop\n        }\n      ]);\n    }\n  }\n&lt;\/script&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20210409154859.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3209\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20210409154859.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20210409154859\" width=\"230\" height=\"546\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">iscroll-sticky.js<\/code> \u53ef\u6309\u9700\u6c42\u6539\u9009\u62e9\u5668\u548c top\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u516b\u3001\u4e0b\u62c9\u5237\u65b0<\/h2>\n<p style=\"margin: 1em 0px;\">\u5e93\u672c\u8eab\u6ca1\u6709\u4e0b\u62c9\u5237\u65b0\uff0c\u8981\u81ea\u5df1\u505a\u3002\u7528 status \u8bb0\u5f55\u72b6\u6001\uff0c\u53d8\u5316\u65f6 refresh \u597d\u91cd\u65b0\u91cf DOM\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">export default {\n  data() {\n    scroll: null,\n    status: 0, \/\/ \u7528\u4e00\u4e2a\u53d8\u91cf\u8bb0\u5f55iscroll\u6eda\u52a8\u72b6\u6001\uff0c\u9ed8\u8ba4\u4e3a0\n    txt: '\u4e0b\u62c9\u5237\u65b0', \/\/ \u8bb0\u5f55\u5237\u65b0\u6587\u672c\uff0c\u9ed8\u8ba4\n  },\n  watch: {\n    status() {\n      \/\/ \u6bcf\u6b21iscroll\u7684\u72b6\u6001\u7801\u53d8\u5316\u65f6\uff0c\u5c31\u8981\u5237\u65b0iscroll\uff0c\u4ee5\u4fbfiscroll\u91cd\u65b0\u8ba1\u7b97dom\u5143\u7d20\n      this.iscroll.refresh();\n    }\n  }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5237\u65b0\u6587\u6848\u9ed8\u8ba4\u85cf\u5728\u5bb9\u5668\u5916\uff08top: -50px\uff09\uff0cstatus \u975e 0 \u518d\u8fdb\u6765\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;template&gt;\n  &lt;div ref=\"scroll\" class=\"wrap\"&gt;\n    &lt;div class=\"scroll-area\"&gt;\n      &lt;div :class=\"{hide: status===0}\" class=\"refresh\"&gt;{{ txt }}&lt;\/div&gt;\n      &lt;div v-for=\"n in 50\" class=\"item\"&gt;{{ n }}&lt;\/div&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n.refresh{\n  width: 100%;\n  height: 50px;\n  line-height: 50px;\n  text-align: center;\n  &amp;.hide{\n    \/* \u5f53status\u4e3a0\u9ed8\u8ba4\u65f6\uff0c\u9690\u85cf\u5237\u65b0\u6587\u672c\uff0c\u901a\u8fc7\u5b9a\u4f4d\u5230\u5bb9\u5668\u5916\u9762 *\/\n    position: absolute;\n    left: 0;\n    top: -50px;\n  }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u4e0b\u62c9 y \u4e3a\u6b63\uff1b\u8d85\u8fc7\u6587\u6848\u9ad8\u5ea6\u628a status \u7f6e 1\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\/\/ ...\nthis.scroll.on('scroll', e =&gt; {\n  const y = this.iscroll.y; \/\/ \u76d1\u542c\u4e0b\u62c9\u7684y\u503c\uff0c\u4e0b\u62c9\u662f\u6b63\u503c\n  if (y &gt;= 50) { \/\/ \u5f53\u4e0b\u62c9\u8ddd\u79bb&gt;=\u5237\u65b0\u6587\u672c\u9ad8\u5ea6\u65f6,\n    this.status = 1; \/\/ \u72b6\u6001\u7801\u53d8\u4e3a1, \u8868\u793a\u51c6\u5907\u597d\u5237\u65b0\u4e86\n  }\n})<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u624b\u6307\u672a\u653e\u4ecd\u662f\u51c6\u5907\u5237\u65b0\u3002\u518d\u542c scroll \u56de\u5f39\u548c scrollEnd \u771f\u6b63\u5237\u65b0\uff08\u539f\u6587\u542b\u300c\u590d\u5236\u4ee3\u7801\u300d\u5206\u9694\uff09\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">this.scroll.on('scroll', e =&gt; {\n  const y = this.iscroll.y; \/\/ \u76d1\u542c\u4e0b\u62c9\u7684y\u503c\uff0c\u4e0b\u62c9\u662f\u6b63\u503c\n  if (y &gt;= 50) { \/\/ \u5f53\u4e0b\u62c9\u8ddd\u79bb&gt;=\u5237\u65b0\u6587\u672c\u9ad8\u5ea6\u65f6,\n    this.txt = '\u91ca\u653e\u5237\u65b0';\n    this.status = 1; \/\/ \u72b6\u6001\u7801\u53d8\u4e3a1, \u8868\u793a\u51c6\u5907\u597d\u5237\u65b0\u4e86\n  } else if (y &gt; 0) { \/\/ \u5982\u679c\u8fd4\u56de\u4e86\uff0c\u53c8\u4e0d\u60f3\u5237\u65b0\u4e86,\u6062\u590dstatus\u4e3a0\n\tthis.txt = '\u4e0b\u62c9\u5237\u65b0';\n\tthis.status = 0;\n  }\n})\nthis.scroll.on('scrollEnd', e =&gt; {\n  if (status === 1) { \/\/ \u6eda\u52a8\u505c\u6b62\u65f6\uff0c\u5982\u679c\u662f\u51c6\u5907\u5237\u65b0\u72b6\u6001\n    this.txt = '\u5237\u65b0\u4e2d\u3002\u3002\u3002';\n    this.status = 2; \/\/ \u6539\u53d8\u72b6\u6001\u7801\uff0c\u5f00\u59cb\u5237\u65b0\n    this.scroll.disable(); \/\/ \u5237\u65b0\u8fc7\u7a0b\u7981\u6b62\u6eda\u52a8\uff0c\u8fd9\u4e2a\u7981\u7528\u65b9\u6cd5\u89c6\u9700\u6c42\u800c\u5b9a\u3002\n    this.updateData(); \/\/ \u5047\u8bbe\u6709\u4e00\u4e2a\u66f4\u65b0\u6570\u636e\u7684method\n  }\n})\n\u590d\u5236\u4ee3\u7801\nexport default {\n  methods: {\n    updateData() {\n      getData().then(_=&gt;{\n        \/\/ \u6570\u636e\u66f4\u65b0\u5b8c\u6210\n        this.txt = '\u5237\u65b0\u5b8c\u6210';\n        \/\/ \u5ef6\u8fdf1\u79d2\u540e\u7ee7\u7eed\u9690\u85cf\u5237\u65b0\u6587\u672c\n        setTimeout(_=&gt;{\n          this.txt = '\u4e0b\u62c9\u5237\u65b0';\n          this.status = 0; \/\/ \u72b6\u6001\u91cd\u7f6e\u4e3a0\n          this.scroll.enable();\n        }, 1000);\n      })\n    }\n  }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6548\u679c\u4e0e\u732b\u773c\u7535\u5f71 demo\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20210409154917.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3210\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20210409154917.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20210409154917\" width=\"227\" height=\"509\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20210409155004.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3211\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20210409155004.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20210409155004\" width=\"351\" height=\"257\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/user-gold-cdn.xitu.io\/2019\/5\/21\/16ad92afd07f43a5?imageslim\" alt=\"\u6548\u679c8\" \/><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e5d\u3001\u4e0a\u62c9\u52a0\u8f7d<\/h2>\n<p style=\"margin: 1em 0px;\">\u5224\u65ad\u89e6\u5e95\u5373\u53ef\uff08y \u4e3a\u8d1f\uff0c\u7528\u5bb9\u5668\u9ad8\u51cf\u5185\u5bb9\u9ad8\uff09\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">this.scroll.on('scroll', e =&gt; {\n  \/\/ \u6b64\u5904scrollEl\u662f\u5bb9\u5668\u9ad8\u5ea6\uff0ccontentEl\u662f\u5185\u5bb9\u9ad8\u5ea6\uff0c\u56e0\u4e3ay\u662f\u8d1f\u503c\uff0c\u6240\u4ee5\u7528scrollEl - contentEl\n  if (this.scroll.y &lt;= scrollEl.offsetHeight - contentEl.offsetHeight) {\n    \/\/ do something \u4e0a\u62c9\u52a0\u8f7d\n  }\n});<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u5341\u3001\u7ed3\u6784\u7ea6\u5b9a\u4e0e\u5907\u6ce8<\/h2>\n<p style=\"margin: 1em 0px;\">\u5e93\u5f88\u7075\u6d3b\u3002\u719f\u6089\u6a21\u5757\u5316\u7684\u8bdd\uff0c\u53ef\u4ee5\u628a sticky\u3001\u4e0b\u62c9\u5237\u65b0\u3001\u4e0a\u62c9\u52a0\u8f7d\u5c01\u8fdb\u4e00\u4e2a\u7ec4\u4ef6\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u8f6c\u81f3\uff1a<a class=\"url\" href=\"https:\/\/juejin.cn\/post\/6844903847941390349#heading-0\" target=\"_blank\">https:\/\/juejin.cn\/post\/6844903847941390349#heading-0<\/a><\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>iScroll \u5b98\u7f51\u53ef\u80fd\u8bbf\u95ee\u4e0d\u4e86\uff08<a href=\"https:\/\/links.jianshu.com\/go?to=http%3A%2F%2Fiscrolljs.com%2F\">iscrolljs.com<\/a>\uff09<\/section>\n<\/li>\n<li>\n<section>GitHub <a href=\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fgithub.com%2Fcubiq%2Fiscroll\">https:\/\/github.com\/cubiq\/iscroll<\/a>\uff0cbuild \u6587\u4ef6\u5939\u91cc\u662f\u5404\u7248\u672c<\/section>\n<\/li>\n<li>\n<section>\u4e2d\u6587\u6587\u6863 <a href=\"https:\/\/links.jianshu.com\/go?to=http%3A%2F%2Fcaibaojian.com%2Fiscroll-5%2Fversions.html\">http:\/\/caibaojian.com\/iscroll-5\/versions.html<\/a><\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u5fc5\u987b\u4e09\u5c42\u7ed3\u6784\uff08\u6eda\u52a8\u5bb9\u5668 \u2192 \u6570\u636e\u5bb9\u5668 \u2192 \u6570\u636e\u9879\uff09\uff0c\u4f8b\u5982 div\u2192ul\u2192li \u6216\u4e09\u5c42 div\u3002\u5bb9\u5668\u81f3\u5c11 overflow:hidden \u548c position:relative\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;style&gt;\n    * {\n        margin: 0;\n    }\n    .wrapper {\n        width: 300px;\n        height: 200px;\n        overflow: hidden; \/* \u9690\u85cf\u9ed8\u8ba4\u6eda\u52a8\u6761 *\/\n        border: 1px solid #0094ff;\n        margin: 0 auto;\n        position: relative; \/* \u5fc5\u987b\u4e3a \u6eda\u52a8\u6761 \u7236\u5bb9\u5668\u8bbe\u7f6e\u5b9a\u4f4d *\/\n    }\n&lt;\/style&gt;\n&lt;!--1.\u4e09\u5c42\u7ed3\u6784--&gt;\n&lt;div id=\"wrapper\"&gt;\n    &lt;ul&gt;\n        &lt;li&gt;...&lt;\/li&gt;\n        &lt;li&gt;...&lt;\/li&gt;\n        ...\n    &lt;\/ul&gt;\n&lt;\/div&gt;\n&lt;!--2.\u521d\u59cb\u5316--&gt;\n&lt;script type=\"text\/javascript\" src=\"iscroll.js\"&gt;&lt;\/script&gt;\n&lt;script type=\"text\/javascript\"&gt;\n    new IScroll('#wrapper', {\n        mouseWheel: true, \/\/ \u9f20\u6807\u6eda\u8f6e\u63a7\u5236 \n        scrollbars: true \/\/\u6eda\u52a8\u6761\u7684\u663e\u793a\n    })\n&lt;\/script&gt;<\/code><\/pre>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u53ef\u5728 PC\u3001\u79fb\u52a8\u8bbe\u5907\u548c\u667a\u80fd\u7535\u89c6\u5de5\u4f5c<\/section>\n<\/li>\n<li>\n<section>\u80fd\u5904\u7406\u6eda\u52a8\u3001\u7f29\u653e\u3001\u5e73\u79fb\u3001\u65e0\u9650\u6eda\u52a8\u3001\u89c6\u5dee\u6eda\u52a8\u3001\u65cb\u8f6c\u7b49\u4ea4\u4e92<\/section>\n<\/li>\n<\/ul>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u80fd\u529b<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u8981\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u521d\u59cb\u5316<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4e09\u5c42 DOM + overflow:hidden + mounted \u91cc new IScroll<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5f02\u6b65\u5185\u5bb9<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">refresh()<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4f4d\u7f6e<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">probeType: 3 + on(&#8216;scroll&#8217;)<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8d34\u5408<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">snap<\/code> + <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">goToPage<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5438\u9876<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5230\u8fbe\u9608\u503c\u540e\u53cd\u5411 transform<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5237\u65b0\/\u52a0\u8f7d<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u81ea\u5df1\u542c y \u4e0e\u89e6\u5e95<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aiScroll \u7528 transform \u6a21\u62df\u539f\u751f\u6eda\u52a8\uff1b\u56fa\u5b9a\u9ad8\u5ea6\u9690\u85cf\u6ea2\u51fa\uff0c\u5f02\u6b65\u540e refresh\uff0c\u9700\u8981\u5438\u9876\u3001\u5237\u65b0\u3001\u52a0\u8f7d\u65f6\u5728 scroll \u4e8b\u4ef6\u4e0a\u81ea\u5df1\u7b97\u4f4d\u79fb\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0d\u5c11\u573a\u666f\u7528 body \u6eda\u52a8\u4e0d\u65b9\u4fbf\uff0c\u53ea\u80fd\u5c40\u90e8\u6eda\u52a8\uff1aWindows \u6d4f\u89c8\u5668\u6eda\u52a8\u6761\u96be\u770b\uff0ciOS \u9ed8\u8ba4\u6ca1\u6709\u60ef\u6027\u548c\u5f39\u6027\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[109,105],"tags":[150,155],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3202"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3202"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3202\/revisions"}],"predecessor-version":[{"id":3212,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3202\/revisions\/3212"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}