aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw
diff options
context:
space:
mode:
authorIrvin <irvinfly@gmail.com>2022-03-02 13:14:10 +0800
committerIrvin <irvinfly@gmail.com>2022-03-02 13:14:49 +0800
commit10ea883d7f303e49a2b48319bee2acd828a979d2 (patch)
treedfd32675edbfdd4faf38535ee87f0b4be3c17145 /files/zh-tw
parent79f89eebf857db081bc99ea7dbe61c009b79b85d (diff)
downloadtranslated-content-10ea883d7f303e49a2b48319bee2acd828a979d2.tar.gz
translated-content-10ea883d7f303e49a2b48319bee2acd828a979d2.tar.bz2
translated-content-10ea883d7f303e49a2b48319bee2acd828a979d2.zip
slightly update translation refer to original ver
Diffstat (limited to 'files/zh-tw')
-rw-r--r--files/zh-tw/web/api/document/scroll_event/index.md12
1 files changed, 9 insertions, 3 deletions
diff --git a/files/zh-tw/web/api/document/scroll_event/index.md b/files/zh-tw/web/api/document/scroll_event/index.md
index a7c765d68e..df146d821f 100644
--- a/files/zh-tw/web/api/document/scroll_event/index.md
+++ b/files/zh-tw/web/api/document/scroll_event/index.md
@@ -15,7 +15,7 @@ browser-compat: api.Document.scroll_event
---
{{APIRef}}
-**`scroll`** 事件會在捲動document檢視區時觸發。Element元件捲動相關請參見{{domxref("Element/scroll_event", "Element:&nbsp;scroll事件")}}。
+**`scroll`** 事件會在捲動文件的可視區域時觸發。元件(Element)捲動相關請參見{{domxref("Element/scroll_event", "Element:&nbsp;scroll事件")}}。
<table class="properties">
<tbody>
@@ -46,7 +46,13 @@ browser-compat: api.Document.scroll_event
### 限制捲動事件的觸發次數
-有鑒於`scroll`事件可能會以很高的速率觸發,事件處理常式不應執行計算密集的操作(如DOM修改)。DOM修改建議改用{{DOMxRef("Window.requestAnimationFrame()", "requestAnimationFrame()")}}、{{DOMxRef("setTimeout()")}}或{{DOMxRef("CustomEvent")}}限制事件的觸發次數,如下。
+Since scroll events can fire at a high rate, the event handler shouldn't execute computationally expensive operations such as DOM modifications. Instead, it is recommended to throttle the event using requestAnimationFrame(), setTimeout(), or a CustomEvent, as follows.
+
+Note, however, that input events and animation frames are fired at about the same rate, and therefore the optimization below is often unnecessary. This example optimizes thescroll event for requestAnimationFrame.
+
+
+
+有鑒於`scroll`事件可能會以很高的速率觸發,事件處理常式不應執行計算密集的操作(如DOM修改)。所以,建議改用{{DOMxRef("Window.requestAnimationFrame()", "requestAnimationFrame()")}}、{{DOMxRef("setTimeout()")}}或{{DOMxRef("CustomEvent")}}以調控事件的觸發次數,如下。
不過需要注意,輸入事件和動畫影格的觸發速率大致相同,因此通常沒有必要進行下述的最佳化。本範例最佳化`requestAnimationFrame`的`scroll`事件。
@@ -57,7 +63,7 @@ let lastKnownScrollPosition = 0;
let ticking = false;
function doSomething(scrollPos) {
- // 依據捲動位置進行操作
+ // 依據捲動位置進行某些操作
}
document.addEventListener('scroll', function(e) {