Skip to content

Commit 8d9a3ef

Browse files
authored
Merge pull request #1452 from sveltejs/transition-args
Transition args
2 parents c37e6a7 + 5685301 commit 8d9a3ef

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/shared/transitions.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export function generateRule({ a, b, delta, duration }, ease, fn) {
1111

1212
for (let p = 0; p <= 1; p += step) {
1313
const t = a + delta * ease(p);
14-
keyframes += p * 100 + `%{${fn(t)}}\n`;
14+
keyframes += p * 100 + `%{${fn(t, 1 - t)}}\n`;
1515
}
1616

17-
return keyframes + `100% {${fn(b)}}\n}`;
17+
return keyframes + `100% {${fn(b, 1 - b)}}\n}`;
1818
}
1919

2020
// https://github.com/darkskyapp/string-hash/blob/master/index.js
@@ -35,10 +35,10 @@ export function wrapTransition(component, node, fn, params, intro) {
3535
if (intro) {
3636
if (obj.css && obj.delay) {
3737
cssText = node.style.cssText;
38-
node.style.cssText += obj.css(0);
38+
node.style.cssText += obj.css(0, 1);
3939
}
4040

41-
if (obj.tick) obj.tick(0);
41+
if (obj.tick) obj.tick(0, 1);
4242
}
4343

4444
return {
@@ -102,14 +102,14 @@ export function wrapTransition(component, node, fn, params, intro) {
102102

103103
const p = now - program.start;
104104
this.t = program.a + program.delta * ease(p / program.duration);
105-
if (obj.tick) obj.tick(this.t);
105+
if (obj.tick) obj.tick(this.t, 1 - this.t);
106106
},
107107

108108
done() {
109109
const program = this.program;
110110
this.t = program.b;
111111

112-
if (obj.tick) obj.tick(this.t);
112+
if (obj.tick) obj.tick(this.t, 1 - this.t);
113113

114114
component.fire(`${program.b ? 'intro' : 'outro'}.end`, { node });
115115

@@ -133,7 +133,7 @@ export function wrapTransition(component, node, fn, params, intro) {
133133

134134
abort() {
135135
if (this.program) {
136-
if (obj.tick) obj.tick(1);
136+
if (obj.tick) obj.tick(1, 0);
137137
if (obj.css) transitionManager.deleteRule(node, this.program.name);
138138
this.program = this.pending = null;
139139
this.running = false;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default {
2+
skipIntroByDefault: true,
3+
nestedTransitions: true,
4+
intro: true,
5+
6+
test(assert, component, target, window, raf) {
7+
const div = target.querySelector('div');
8+
assert.equal(div.foo, 0);
9+
assert.equal(div.oof, 1);
10+
11+
raf.tick(50);
12+
assert.equal(div.foo, 0.5);
13+
assert.equal(div.oof, 0.5);
14+
}
15+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div transition:foo></div>
2+
3+
<script>
4+
export default {
5+
transitions: {
6+
foo(node, params) {
7+
return {
8+
duration: 100,
9+
tick: (t, u) => {
10+
node.foo = t;
11+
node.oof = u;
12+
}
13+
};
14+
}
15+
}
16+
};
17+
</script>

0 commit comments

Comments
 (0)