tweenjs / tweenjs/tween.js

When the browser tab sleeps, the delay of repeated tweens is not keep

Open
#557 1 comment 0 reactions 0 assignees View on GitHub

A pull request for this has already been merged.

  • #564 by @MasatoMakino — merged
Dominant language
TypeScript
Stars
10.1k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

Description

When the browser tab goes into the background, the delay of repeated tween is not keep.

Expected Behavior

Tabs are restored from the background, the delay of tween is unchanged.

Actual Behavior

Tabs are restored from the background, the delay of tween changes.

Steps to Reproduce

  1. open https://codepen.io/masatomakino/pen/QWyQpYY
  2. open new tab.
  3. change the tab of codepen to the background and wait 5 seconds. ( = tween._repeatDelayTime)
  4. change the codepen tab to foreground.
  5. delay of tween is not kept.

Possible Fix

When the browser tabs are in the background, requestAnimationFrame will go to sleep. requestAnimationFrame will return, and the pass large delta time.

However, tween.js loop does not take large delta time.

elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed

source code

In this process, time is rounded to elapsed. And the delta time disappears.

const overflowCounter = Math.trunc((time - this._startTime) / this._duration);
const overflowTime = (time - this._startTime) % this._duration;

For example, we get an overflow for this process. You can use this value to modify this._repeat and this._startTime.

source code

Environment

macOS 10.15.2
Chrome 83.0.4103.116 (Official Build)
tween.js 18.6.0

Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the merged pull request #564 alongside src/Tween.ts, especially the elapsed-time handling around lines 349 and 386. Reproduce the CodePen case with a backgrounded browser tab, then verify that repeated tween delay remains unchanged after the tab returns to the foreground.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.