瀏覽代碼

fixed doubleclick accuracy problem.

Ievgen Naida 5 年之前
父節點
當前提交
357218c3c4
共有 4 個文件被更改,包括 19 次插入2 次删除
  1. 1 1
      demo/index.html
  2. 7 0
      lib/animation-timeline.js
  3. 0 0
      lib/animation-timeline.min.js
  4. 11 1
      src/timeline.ts

+ 1 - 1
demo/index.html

@@ -149,7 +149,7 @@
     timeline.onDragStarted(function (obj) { dragHandler(obj, 'dragstarted') });
     timeline.onDrag(function (obj) { dragHandler(obj, 'drag') });
     timeline.onDragFinished(function (obj) { dragHandler(obj, 'dragfinished') });
-
+    timeline.on('doubleclick',function (obj) { alert(obj.val); });
   </script>
 </body>
 

+ 7 - 0
lib/animation-timeline.js

@@ -939,6 +939,8 @@ var timeline_Timeline = /*#__PURE__*/function (_TimelineEventsEmitte) {
 
     timeline_defineProperty(timeline_assertThisInitialized(_this), "lastClickTime", 0);
 
+    timeline_defineProperty(timeline_assertThisInitialized(_this), "lastClickPoint", null);
+
     timeline_defineProperty(timeline_assertThisInitialized(_this), "consts", new TimelineConsts());
 
     timeline_defineProperty(timeline_assertThisInitialized(_this), "clickAllowed", false);
@@ -1071,8 +1073,13 @@ var timeline_Timeline = /*#__PURE__*/function (_TimelineEventsEmitte) {
 
       if (!_this.startPos) {
         return;
+      } // Don't allow to perform double click if mouse was moved to far.
+
+
+      if (_this.lastClickPoint && _this.startPos && TimelineUtils.getDistance(_this.lastClickPoint.x, _this.lastClickPoint.y, _this.startPos.x, _this.startPos.y) > _this.consts.clickThreshold) {//  isDoubleClick = false;
       }
 
+      _this.lastClickPoint = _this.startPos;
       _this.scrollStartPos = {
         x: _this.scrollContainer.scrollLeft,
         y: _this.scrollContainer.scrollTop

文件差異過大導致無法顯示
+ 0 - 0
lib/animation-timeline.min.js


+ 11 - 1
src/timeline.ts

@@ -72,6 +72,7 @@ export class Timeline extends TimelineEventsEmitter {
 
   private clickTimeout? = 0;
   private lastClickTime = 0;
+  private lastClickPoint: DOMPoint | null = null;
   private consts = new TimelineConsts();
   private clickAllowed = false;
   /**
@@ -310,14 +311,23 @@ export class Timeline extends TimelineEventsEmitter {
    * @param args
    */
   private handleMouseDownEvent = (args: MouseEvent): void => {
-    const isDoubleClick = Date.now() - this.lastClickTime < this.consts.doubleClickTimeoutMs;
+    let isDoubleClick = Date.now() - this.lastClickTime < this.consts.doubleClickTimeoutMs;
 
     // Prevent drag of the canvas if canvas is selected as text:
     TimelineUtils.clearBrowserSelection();
+
     this.startPos = this.trackMousePos(this.canvas, args);
+
     if (!this.startPos) {
       return;
     }
+
+    // Don't allow to perform double click if mouse was moved to far.
+    if (this.lastClickPoint && this.startPos && TimelineUtils.getDistance(this.lastClickPoint.x, this.lastClickPoint.y, this.startPos.x, this.startPos.y) > this.consts.clickThreshold) {
+      isDoubleClick = false;
+    }
+
+    this.lastClickPoint = this.startPos;
     this.scrollStartPos = {
       x: this.scrollContainer.scrollLeft,
       y: this.scrollContainer.scrollTop,

部分文件因文件數量過多而無法顯示