From e6ad74689093455bc8e519ae1dcfa01bcd7e409b Mon Sep 17 00:00:00 2001 From: "fyue(GongJinJun)" <544648788@qq.com> Date: Sun, 3 Jun 2018 15:02:28 +0800 Subject: [PATCH] Fixed the bug that when emit(stop) the requestAnimationFrame callback still run --- src/tracking.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tracking.js b/src/tracking.js index 6fcc498..28a7881 100644 --- a/src/tracking.js +++ b/src/tracking.js @@ -245,9 +245,10 @@ // it seems all handled in the tracking.TrackerTask.. // so in short, remove the tracking.TrackerTask from here // if the user want to use it, it can create it himself - var requestId; + var stopRequestAnimationFrame = false; var requestAnimationFrame_ = function() { - requestId = window.requestAnimationFrame(function() { + window.requestAnimationFrame(function() { + if (stopRequestAnimationFrame) return; if (element.readyState === element.HAVE_ENOUGH_DATA) { try { // Firefox v~30.0 gets confused with the video readyState firing an @@ -263,7 +264,7 @@ var task = new tracking.TrackerTask(tracker); task.on('stop', function() { - window.cancelAnimationFrame(requestId); + stopRequestAnimationFrame = true; }); task.on('run', function() { requestAnimationFrame_();