Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel animation #13

Open
wants to merge 1 commit into
base: beta-3
Choose a base branch
from
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
12 changes: 9 additions & 3 deletions dist/morphist.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
.morphist > * {
.morphist > *:not(.animated) {
display: none;
}

.morphist > .animated {
display: inline-block;
.morphist.sync {
position: relative;
overflow: hidden;
}
.morphist.sync > * {
position: absolute;
width: 100%;
height: 100%;
}
9 changes: 7 additions & 2 deletions dist/morphist.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
animateIn: "bounceIn",
animateOut: "rollOut",
speed: 2000,
sync: false,
complete: $.noop
};

Expand All @@ -39,6 +40,9 @@
"MSAnimationEnd oanimationend animationend";

this.children = this.element.children();
if (this.settings.sync && this.children[0]) {
this.element.addClass("sync").height(this.children[0].clientHeight + "px");
}
this.element.addClass("morphist");

this.index = 0;
Expand All @@ -64,15 +68,16 @@
$current.removeClass();
$that._shouldForceReflow($current);

$that.index = ++$that.index % $that.children.length;
$that._animate(
$current,
"mis-out " + $that.settings.animateOut,
function () {
$that.index = ++$that.index % $that.children.length;
$current.removeClass();
$that.loop();
if (!$that.settings.sync) $that.loop();
}
);
if ($that.settings.sync) $that.loop();
}, $that.settings.speed);
};

Expand Down
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bower_components/animate.css/animate.min.css">
<link rel="stylesheet" href="dist/morphist.css">
<style type="text/css">
.morphist.sync {
padding: 0;
}
.morphist.sync li {
color: white;
}
.morphist.sync li:nth-child(odd) {
background-color: red;
}
.morphist.sync li:nth-child(even) {
background-color: blue;
}
</style>
</head>

<body>
Expand All @@ -19,6 +33,12 @@
<li>Much Wow</li>
<li>Such Cool</li>
</ul>
<ul id="js-rotating-sync">
<li>So Simple</li>
<li>Very Doge</li>
<li>Much Wow</li>
<li>Such Cool</li>
</ul>
...child object rotator.
</div>

Expand All @@ -34,6 +54,11 @@
console.log("This is called after an item is animated in! Current child index: " + this.index);
}
});
$("#js-rotating-sync").Morphist({
animateIn: "slideInRight",
animateOut: "slideOutLeft",
sync: true
});
</script>
</body>
</html>