这是所在行:
|
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><blockquote><p>PS:具体 API 可参考 <a href="/kbone/docs/domextend/">dom/bom 扩展 API</a> 文档。</p></blockquote> <h2 id="事件系统扩展"><a href="#事件系统扩展" class="header-anchor">#</a> 事件系统扩展</h2> <p>kbone 里节点事件没有直接复用小程序的捕获冒泡事件体系,原因在于:</p> <ul><li>小程序事件和 Web 事件不完全对齐,比如 input 事件在小程序里是不冒泡的。</li> <li>小程序自定义组件是基于 Web Components 的概念设计的,对于跨自定义组件的情况,无法准确获取事件的源节点。</li></ul> <p>故在 kbone 里的节点事件是在源节点里监听到后,就直接在 kbone 仿造出的 dom 树中进行捕获冒泡。此处使用的事件绑定方式均采用 bindxxx 的方式,故在小程序中最初监听到的事件一定是在源节点监听到的。比如用户触摸屏幕后,会触发 touchstart 事件,在节点 a 上监听到 touchstart 事件后,后续监听到同一行为触发的 touchstart 均会被抛弃,后续的捕获冒泡阶段会在仿造 dom 树中进行。</p> <p>目前除了内置组件特有的事件外(比如图片的 load 事件),普通节点只有 <strong>touchstart</strong>、<strong>touchmove</strong>、<strong>touchend</strong>、<strong>touchcancel</strong> 和 <strong>tap</strong> 会被监听,其中 tap 会被转化为 <strong>cick</strong> 事件来触发。</p> <p>因为此处事件监听方式默认是 bindxxx,但是对于一些特殊场景可能需要使用小程序的 capture-bind:xxx(比如无法在源节点监听到事件的场景)、catchxxx(比如需要阻止触摸引起滚动的场景) 和动画事件的情况,对于此可以使用特殊节点 <code>wx-capture</code>、<code>wx-catch</code> 和 <code>wx-animation</code>:</p> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token comment"><!-- 使用小程序原生方式监听 capture 事件 --></span> |