Skip to content

Commit

Permalink
cleanup and gsap fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nico committed Aug 15, 2023
1 parent b32039e commit 8df7dff
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 86 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ A web page with a menu, a picture and some text doesn't require 2Mb JS code.

# Demo

https://nicopowa.github.io/effect/
https://nicopowa.github.io/effect/index.html

same code with gsap wrapper : https://nicopowa.github.io/effect/gsap.html

# How it works
- play all effects from a single frame loop
Expand Down
3 changes: 1 addition & 2 deletions compile.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"package": {
"output_file": "js/main.min.js",
"files": [
"js/effect.js",
"js/main.js"
],
"output_style": "css/main.min.css",
Expand All @@ -57,7 +56,7 @@

],
"externs": [

"effect"
],
"comment": "© ILUSIO %year https://blog.ilusio.dev"
}
Expand Down
1 change: 1 addition & 0 deletions css/effect.package.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions effect.bundle.min.js

This file was deleted.

4 changes: 2 additions & 2 deletions gsap.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

<link rel="stylesheet" href="css/style.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<script src="js/effect.gsap.js"></script>
<script src="js/test_effect.js"></script>
<script src="js/main.js"></script>

</head>
<body>
Expand Down
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<link rel="stylesheet" href="css/main.min.css">

<script src="js/main.min.js"></script>
<script src="js/effect.default.release.min.js"></script>
<script src="js/effect.package.release.min.js"></script>

</head>

Expand Down
10 changes: 0 additions & 10 deletions js/effect.debug.min.js

This file was deleted.

71 changes: 49 additions & 22 deletions js/effect.gsap.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,65 @@
window.isGSAP = true;

class Effect { // unify Effect & TweenMax calls

//target, frames, props, ease, delay, override, callback

constructor(target, frames, props, ease, delay, override, callback) {
ease = ease || "no";
delay = delay * toSec || 0;

this.target = target;
this.secs = frames * toSec;
this.callback = callback || function() {};
this.params = Object.assign(props, {delay: delay, ease: Effect.ease(ease)});
this.params = Object.assign(props, {duration: frames * toSec, delay: (delay || 0) * toSec, ease: ease()});

}

play() {
return Effect.asyncTween(this.target, this.secs, this.params, this.callback);

return Effect.asyncTween(this.target, this.params, this.callback);

}

static no() {

return Linear.easeNone;

}

static ease(name) {
let eases = {
"no": Linear.easeNone,
"quartIn": Quart.easeIn,
"quartOut": Quart.easeOut,
"quartInOut": Quart.easeInOut,
"bounceOut": Bounce.easeOut
};
return eases[name];
static quartOut() {

return Quart.easeOut;

}

static asyncTween(target, duration, options, callback) { // savage TweenMax onComplete promise
return new Promise(resolve => TweenMax.to(target, duration, Object.assign(options, {"onComplete": function() {
callback();
resolve();
}})));
static quartIn() {

return Quart.easeIn;

}

/*static asyncTween(target, duration, options) {
return new Promise(resolve => TweenMax.to(target, duration, Object.assign(options, {"onComplete": resolve}))); // savage TweenMax onComplete promise
}*/
static quartInOut() {

return Quart.easeInOut;

}

static bounceOut() {

return Bounce.easeOut;

}

static asyncTween(target, options, callback) {

return gsap
.to(
target,
options
)
.then(
() =>
callback()
);

}

}
10 changes: 0 additions & 10 deletions js/effect.min.js

This file was deleted.

20 changes: 20 additions & 0 deletions js/effect.package.release.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ function square(left, top, width, height, index) {

async function main() {

Effect["bounceOut"] = function(t, b, c, d) { // some bounce
if((t /= d) < (1 / 2.75)) return c * (7.5625 * t * t) + b;
else if(t < (2 / 2.75)) return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
else if(t < (2.5 / 2.75)) return c * (7.5625 * (t -= (2.25 / 2.75))*t + .9375) + b;
else return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
}
if(typeof window["isGSAP"] === "undefined")
Effect["bounceOut"] = function(t, b, c, d) { // some bounce
if((t /= d) < (1 / 2.75)) return c * (7.5625 * t * t) + b;
else if(t < (2 / 2.75)) return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
else if(t < (2.5 / 2.75)) return c * (7.5625 * (t -= (2.25 / 2.75))*t + .9375) + b;
else return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
};

let sq1 = square(10, 10, 100, 100, "click me");
sq1.style.backgroundColor = "rgb(255, 0, 0)";
Expand Down
Loading

0 comments on commit 8df7dff

Please sign in to comment.