Skip to content

Commit d4ea2de

Browse files
committed
Use interpolation for steps
1 parent 552db83 commit d4ea2de

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

easycoder/plugins/vfx.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ const EasyCoder_VFX = {
170170
let heightS = height * zoomS;
171171
animation.leftS = width * zoomS * spec.start.left / 100;
172172
animation.topS = height * zoomS * spec.start.top / 100;
173-
let widthF = width * 100 / spec.finish.width;
174-
let zoomF = widthF / width;
173+
animation.widthF = width * 100 / spec.finish.width;
174+
let zoomF = animation.widthF / width;
175175
let heightF = height * zoomF;
176-
let leftF = width * zoomF * spec.finish.left / 100;
177-
let topF = height * zoomF * spec.finish.top / 100;
176+
animation.leftF = width * zoomF * spec.finish.left / 100;
177+
animation.topF = height * zoomF * spec.finish.top / 100;
178178

179179
if (spec.start.width > 100) {
180180
throw new Error(`Start width too great for item ${targetRecord.index}`);
@@ -188,16 +188,12 @@ const EasyCoder_VFX = {
188188
if (heightS - animation.topS < height) {
189189
throw new Error(`Insufficient start height for item ${targetRecord.index}`);
190190
}
191-
if (widthF - leftF < width) {
191+
if (animation.widthF - animation.leftF < width) {
192192
throw new Error(`Insufficient finish width for item ${targetRecord.index}`);
193193
}
194-
if (heightF - topF < height) {
194+
if (heightF - animation.topF < height) {
195195
throw new Error(`Insufficient finish height for item ${targetRecord.index}`);
196196
}
197-
198-
animation.stepL = (leftF - animation.leftS) / spec.steps;
199-
animation.stepT = (topF - animation.topS) / spec.steps;
200-
animation.stepW = (widthF - animation.widthS) / spec.steps;
201197
animation.left = animation.leftS;
202198
animation.top = animation.topS;
203199
animation.width = animation.widthS;
@@ -274,9 +270,10 @@ const EasyCoder_VFX = {
274270
const animation = targetRecord.animation[targetRecord.index];
275271
if (animation.step < animation.spec.steps) {
276272
animation.step++;
277-
animation.left += animation.stepL;
278-
animation.top += animation.stepT
279-
animation.width += animation.stepW;
273+
let proportion = parseFloat(animation.step) / animation.spec.steps;
274+
animation.left = animation.leftS + (animation.leftF - animation.leftS) * proportion;
275+
animation.top = animation.topS + (animation.topF - animation.topS) * proportion;
276+
animation.width = animation.widthS + (animation.widthF - animation.widthS) * proportion;
280277
const image = animation.image;
281278
image.style.left = `-${animation.left}px`;
282279
image.style.top = `-${animation.top}px`;

js/plugins/vfx.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ const EasyCoder_VFX = {
170170
let heightS = height * zoomS;
171171
animation.leftS = width * zoomS * spec.start.left / 100;
172172
animation.topS = height * zoomS * spec.start.top / 100;
173-
let widthF = width * 100 / spec.finish.width;
174-
let zoomF = widthF / width;
173+
animation.widthF = width * 100 / spec.finish.width;
174+
let zoomF = animation.widthF / width;
175175
let heightF = height * zoomF;
176-
let leftF = width * zoomF * spec.finish.left / 100;
177-
let topF = height * zoomF * spec.finish.top / 100;
176+
animation.leftF = width * zoomF * spec.finish.left / 100;
177+
animation.topF = height * zoomF * spec.finish.top / 100;
178178

179179
if (spec.start.width > 100) {
180180
throw new Error(`Start width too great for item ${targetRecord.index}`);
@@ -188,16 +188,12 @@ const EasyCoder_VFX = {
188188
if (heightS - animation.topS < height) {
189189
throw new Error(`Insufficient start height for item ${targetRecord.index}`);
190190
}
191-
if (widthF - leftF < width) {
191+
if (animation.widthF - animation.leftF < width) {
192192
throw new Error(`Insufficient finish width for item ${targetRecord.index}`);
193193
}
194-
if (heightF - topF < height) {
194+
if (heightF - animation.topF < height) {
195195
throw new Error(`Insufficient finish height for item ${targetRecord.index}`);
196196
}
197-
198-
animation.stepL = (leftF - animation.leftS) / spec.steps;
199-
animation.stepT = (topF - animation.topS) / spec.steps;
200-
animation.stepW = (widthF - animation.widthS) / spec.steps;
201197
animation.left = animation.leftS;
202198
animation.top = animation.topS;
203199
animation.width = animation.widthS;
@@ -274,9 +270,10 @@ const EasyCoder_VFX = {
274270
const animation = targetRecord.animation[targetRecord.index];
275271
if (animation.step < animation.spec.steps) {
276272
animation.step++;
277-
animation.left += animation.stepL;
278-
animation.top += animation.stepT
279-
animation.width += animation.stepW;
273+
let proportion = parseFloat(animation.step) / animation.spec.steps;
274+
animation.left = animation.leftS + (animation.leftF - animation.leftS) * proportion;
275+
animation.top = animation.topS + (animation.topF - animation.topS) * proportion;
276+
animation.width = animation.widthS + (animation.widthF - animation.widthS) * proportion;
280277
const image = animation.image;
281278
image.style.left = `-${animation.left}px`;
282279
image.style.top = `-${animation.top}px`;

0 commit comments

Comments
 (0)