瀏覽代碼

call requestAnimationFrame when moving the selection

Gildas 7 年之前
父節點
當前提交
7cc64c065d
共有 1 個文件被更改,包括 8 次插入6 次删除
  1. 8 6
      extension/ui/content/content-ui.js

+ 8 - 6
extension/ui/content/content-ui.js

@@ -118,12 +118,14 @@ this.singlefile.ui = this.singlefile.ui || (() => {
 	}
 
 	function moveAreaSelector(target) {
-		const selectorElement = createAreaSelector();
-		const boundingRect = target.getBoundingClientRect();
-		selectorElement.style.setProperty("top", (scrollY + boundingRect.top - 10) + "px");
-		selectorElement.style.setProperty("left", (scrollX + boundingRect.left - 10) + "px");
-		selectorElement.style.setProperty("width", (boundingRect.width + 20) + "px");
-		selectorElement.style.setProperty("height", (boundingRect.height + 20) + "px");
+		requestAnimationFrame(() => {
+			const selectorElement = createAreaSelector();
+			const boundingRect = target.getBoundingClientRect();
+			selectorElement.style.setProperty("top", (scrollY + boundingRect.top - 10) + "px");
+			selectorElement.style.setProperty("left", (scrollX + boundingRect.left - 10) + "px");
+			selectorElement.style.setProperty("width", (boundingRect.width + 20) + "px");
+			selectorElement.style.setProperty("height", (boundingRect.height + 20) + "px");
+		});
 	}
 
 	function createAreaSelector() {