aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/setpointercapture
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/element/setpointercapture
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/element/setpointercapture')
-rw-r--r--files/zh-cn/web/api/element/setpointercapture/index.html113
1 files changed, 113 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/setpointercapture/index.html b/files/zh-cn/web/api/element/setpointercapture/index.html
new file mode 100644
index 0000000000..401d08e629
--- /dev/null
+++ b/files/zh-cn/web/api/element/setpointercapture/index.html
@@ -0,0 +1,113 @@
+---
+title: Element.setPointerCapture()
+slug: Web/API/Element/setPointerCapture
+tags:
+ - API
+ - DOM
+ - Element
+translation_of: Web/API/Element/setPointerCapture
+---
+<p>{{APIRef("DOM")}}</p>
+
+<p>{{domxref("Element")}}接口的<strong><code>setPointerCapture()</code></strong> 方法用于将特定元素指定为未来指针事件的捕获目标。指针的后续事件将以捕获元素为目标,直到捕获被释放(通过{{domxref("Element.releasePointerCapture()")}})。</p>
+
+<div class="note">一旦设置了pointer capture,  {{event("pointerover")}}, {{event("pointerout")}} {{event("pointerenter")}}, 和{{event("pointerleave")}}  事件将不会被触发,直到越过设置了capture的元素的边界。这是因为其他元素将不能再作为pointer事件的目标了。这会影响到这些事件在其他元素上的触发。</div>
+
+<div>
+<h3 id="指针捕获概述">指针捕获概述</h3>
+</div>
+
+<div>指针捕获允许一个特定的指针事件({{domxref("PointerEvent")}}) 事件从一个事件触发时候的目标重定位到另一个目标上。这个功能可以确保一个元素可以持续的接收到一个pointer事件,即使这个事件的触发点已经移出了这个元素(比如,在滚动的时候)。</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">targetElement.<em>setPointerCapture</em>(pointerId);
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>pointerId</code></dt>
+ <dd>{{domxref("PointerEvent")}} 对象的{{domxref("PointerEvent.pointerId", "pointerId")}} 。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>返回void。如果<code>pointerId</code>不匹配任何当前活动的指针事件,将抛出{{domxref("DOMException")}}。</p>
+
+<h2 id="示例">示例</h2>
+
+<p>当您按下它时,此示例在 {{HtmlElement("div")}} 上设置指针捕获。这使您可以滑动元素,即使指针移动到其边界之外也是如此。</p>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;div id="slider"&gt;SLIDE ME&lt;/div&gt;</pre>
+
+<h3 id="CSS">CSS</h3>
+
+<pre class="brush: css">div {
+ width: 140px;
+ height: 50px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: #fbe;
+}</pre>
+
+<h3 id="JavaScript">JavaScript</h3>
+
+<pre class="brush: js">function beginSliding(e) {
+ slider.onpointermove = slide;
+ slider.setPointerCapture(e.pointerId);
+}
+
+function stopSliding(e) {
+ slider.onpointermove = null;
+ slider.releasePointerCapture(e.pointerId);
+}
+
+function slide(e) {
+ slider.style.transform = `translate(${e.clientX - 70}px)`;
+}
+
+const slider = document.getElementById('slider');
+
+slider.onpointerdown = beginSliding;
+slider.onpointerup = stopSliding;</pre>
+
+<h3 id="结果">结果</h3>
+
+<p>{{EmbedLiveSample("示例")}}</p>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">标准</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Pointer Events 2','#widl-Element-setPointerCapture-void-long-pointerId', 'setPointerCapture')}}</td>
+ <td>{{Spec2('Pointer Events 2')}}</td>
+ <td>不稳定版本</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('Pointer Events', '#widl-Element-setPointerCapture-void-long-pointerId', 'setPointerCapture')}}</td>
+ <td>{{Spec2('Pointer Events')}}</td>
+ <td>初版</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("api.Element.setPointerCapture")}}</p>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>{{ domxref("Element.releasePointerCapture")}}</li>
+ <li>{{ domxref("Pointer_events","Pointer Events") }}</li>
+</ul>