Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/tween.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ define(['exports'], (function (exports) { 'use strict';
}
this._onEveryStartCallbackFired = true;
}
var elapsedTime = time - this._startTime;
var elapsedTime = this._yoyo ? Math.min(time - this._startTime, this._duration) : time - this._startTime;
var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
var totalTime = this._duration + this._repeat * durationAndDelay;
var calculateElapsedPortion = function () {
Expand Down Expand Up @@ -894,7 +894,7 @@ define(['exports'], (function (exports) { 'use strict';
return Tween;
}());

var VERSION = '25.0.0';
var VERSION = '25.0.1';

/**
* Tween.js - Licensed under the MIT license
Expand Down
4 changes: 2 additions & 2 deletions dist/tween.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ var Tween = /** @class */ (function () {
}
this._onEveryStartCallbackFired = true;
}
var elapsedTime = time - this._startTime;
var elapsedTime = this._yoyo ? Math.min(time - this._startTime, this._duration) : time - this._startTime;
var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
var totalTime = this._duration + this._repeat * durationAndDelay;
var calculateElapsedPortion = function () {
Expand Down Expand Up @@ -896,7 +896,7 @@ var Tween = /** @class */ (function () {
return Tween;
}());

var VERSION = '25.0.0';
var VERSION = '25.0.1';

/**
* Tween.js - Licensed under the MIT license
Expand Down
2 changes: 1 addition & 1 deletion dist/tween.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ declare class Sequence {
static nextId(): number;
}

declare const VERSION = "25.0.0";
declare const VERSION = "25.0.1";

declare const nextId: typeof Sequence.nextId;
/**
Expand Down
4 changes: 2 additions & 2 deletions dist/tween.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ var Tween = /** @class */ (function () {
}
this._onEveryStartCallbackFired = true;
}
var elapsedTime = time - this._startTime;
var elapsedTime = this._yoyo ? Math.min(time - this._startTime, this._duration) : time - this._startTime;
var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
var totalTime = this._duration + this._repeat * durationAndDelay;
var calculateElapsedPortion = function () {
Expand Down Expand Up @@ -892,7 +892,7 @@ var Tween = /** @class */ (function () {
return Tween;
}());

var VERSION = '25.0.0';
var VERSION = '25.0.1';

/**
* Tween.js - Licensed under the MIT license
Expand Down
4 changes: 2 additions & 2 deletions dist/tween.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@
}
this._onEveryStartCallbackFired = true;
}
var elapsedTime = time - this._startTime;
var elapsedTime = this._yoyo ? Math.min(time - this._startTime, this._duration) : time - this._startTime;
var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
var totalTime = this._duration + this._repeat * durationAndDelay;
var calculateElapsedPortion = function () {
Expand Down Expand Up @@ -898,7 +898,7 @@
return Tween;
}());

var VERSION = '25.0.0';
var VERSION = '25.0.1';

/**
* Tween.js - Licensed under the MIT license
Expand Down
6 changes: 6 additions & 0 deletions examples/10_yoyo.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ <h2>10 _ yoyo</h2>
<div id="target4" data-rotation="0" data-y="0" class="box" style="left: 600px; top: 0px">
yoyo with repeat forever, relative values
</div>
<div id="target5" data-rotation="0" data-y="0" class="box" style="left: 800px; top: 0px">
yoyo with repeat forever, relative values, without delay
</div>
</div>

<style type="text/css">
Expand Down Expand Up @@ -67,6 +70,9 @@ <h2>10 _ yoyo</h2>
#target4 {
background: skyblue;
}
#target5 {
background: rgb(1, 177, 246);
}
</style>
</body>
</html>
135 changes: 75 additions & 60 deletions examples/10_yoyo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,86 +5,101 @@ const group = new Group()

animate()

const tweenMap = new Map()

const target1 = document.getElementById('target1')
const tween1 = new Tween(target1.dataset, group)
.to({rotation: 360, y: 300}, 750)
.repeat(1)
.delay(1000)
.yoyo(true)
.easing(Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target1, object)
})
.start()
tweenMap.set(
'tween1',
new Tween(target1.dataset, group)
.to({rotation: 360, y: 300}, 750)
.repeat(Infinity)
.delay(1000)
.yoyo(true)
.easing(Easing.Quadratic.InOut)
.onUpdate(function (object) {
updateBox(target1, object)
})
.start(),
)
const target2 = document.getElementById('target2')
const tween2 = new Tween(target2.dataset, group)
.to({rotation: 360, y: 300}, 750)
.repeat(Infinity)
.delay(1000)
.yoyo(true)
.easing(Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target2, object)
})
.start()

tweenMap.set(
'tween2',
new Tween(target2.dataset, group)
.to({rotation: 360, y: 300}, 750)
.repeat(Infinity)
.delay(1000)
.yoyo(true)
.easing(Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target2, object)
})
.start(),
)
const target3 = document.getElementById('target3')
const tween3 = new Tween(target3.dataset, group)
.to({rotation: '+360', y: '+300'}, 750)
.repeat(1)
.delay(1000)
.yoyo(true)
.easing(Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target3, object)
})
.start()
tweenMap.set(
'tween3',
new Tween(target3.dataset, group)
.to({rotation: '+360', y: '+300'}, 750)
.repeat(1)
.delay(1000)
.yoyo(true)
.easing(Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target3, object)
})
.start(),
)
const target4 = document.getElementById('target4')
const tween4 = new Tween(target4.dataset, group)
.to({rotation: '+360', y: '+300'}, 750)
.repeat(Infinity)
.delay(1000)
.yoyo(true)
.easing(Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target4, object)
})
.start()
tweenMap.set(
'tween4',
new Tween(target4.dataset, group)
.to({rotation: '+360', y: '+300'}, 750)
.repeat(Infinity)
.delay(1000)
.yoyo(true)
.easing(Easing.Quadratic.InOut)
.onUpdate(function (object) {
updateBox(target4, object)
})
.start(),
)

const target5 = document.getElementById('target5')
tweenMap.set(
'tween5',
new Tween(target5.dataset, group)
.to({rotation: '+360', y: '+300'}, 1050)
.repeat(Infinity)
// .delay(1000) // without delay
.yoyo(true)
.easing(Easing.Quadratic.InOut)
.onUpdate(function (object) {
updateBox(target5, object)
})
.start(),
)

// TODO perhaps add these methods to Group

const restart = (window.restart = function () {
tween1.stop().start()
tween2.stop().start()
tween3.stop().start()
tween4.stop().start()
tweenMap.forEach(tween => tween.start())
})

const stop = (window.stop = function () {
tween1.stop()
tween2.stop()
tween3.stop()
tween4.stop()
tweenMap.forEach(tween => tween.stop())
})

const start = (window.start = function () {
tween1.start()
tween2.start()
tween3.start()
tween4.start()
tweenMap.forEach(tween => tween.start())
})

const pause = (window.pause = function () {
tween1.pause()
tween2.pause()
tween3.pause()
tween4.pause()
tweenMap.forEach(tween => tween.pause())
})

const resume = (window.resume = function () {
tween1.resume()
tween2.resume()
tween3.resume()
tween4.resume()
tweenMap.forEach(tween => tween.resume())
})

function animate(time) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tweenjs/tween.js",
"description": "Simple and fast tweening engine with optimised Robert Penner's equations.",
"version": "25.0.0",
"version": "25.0.1",
"type": "module",
"main": "dist/tween.cjs",
"types": "dist/tween.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/Tween.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ export class Tween<T extends UnknownProps = any> {
this._onEveryStartCallbackFired = true
}

const elapsedTime = time - this._startTime
const elapsedTime = this._yoyo ? Math.min(time - this._startTime, this._duration) : time - this._startTime

const durationAndDelay = this._duration + (this._repeatDelayTime ?? this._delayTime)
const totalTime = this._duration + this._repeat * durationAndDelay

Expand Down
2 changes: 1 addition & 1 deletion src/Version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const VERSION = '25.0.0'
const VERSION = '25.0.1'
export default VERSION