Skip to content

Commit ea224ac

Browse files
authored
Merge pull request #89 from Doorvest/master
add restart function
2 parents e02c48f + b3815a8 commit ea224ac

File tree

3 files changed

+71
-12
lines changed

3 files changed

+71
-12
lines changed

examples/restart.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>bounty</title>
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
7+
<meta name="author" content="Coderitual" />
8+
<meta name="description" content="Canvas 2d odometer effect" />
9+
<meta
10+
name="viewport"
11+
content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"
12+
/>
13+
<style type="text/css">
14+
@font-face {
15+
font-family: "ITV Reem";
16+
src: url(assets/itvreem.woff) format("woff");
17+
}
18+
19+
body {
20+
background-color: #999;
21+
font-family: "ITV Reem";
22+
font-size: 82px;
23+
text-shadow: 1px 1px 5px rgba(0, 0, 0, 0.5);
24+
fill: #fff;
25+
}
26+
</style>
27+
</head>
28+
29+
<body>
30+
<div class="js-bounty"></div>
31+
<script src="../lib/bounty.js"></script>
32+
<script>
33+
const animation = bounty.default({
34+
el: ".js-bounty",
35+
value: "£42,000,000",
36+
initialValue: "£123,456",
37+
});
38+
39+
const restart = () => {
40+
setInterval(() => {
41+
animation.restart({
42+
el: ".js-bounty",
43+
value: "£56,123,456",
44+
initialValue: "£42,000,000",
45+
})
46+
}, 6000)
47+
}
48+
49+
restart();
50+
</script>
51+
</body>
52+
</html>

lib/bounty.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bounty.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,17 @@ const setViewBox = (svg, width, height) => {
8282
svg::style("overflow", "hidden");
8383
};
8484

85-
export default ({
86-
el,
87-
value,
88-
initialValue = null,
89-
lineHeight = 1.35,
90-
letterSpacing = 1,
91-
animationDelay = 100,
92-
letterAnimationDelay = 100,
93-
duration = 3000,
94-
}) => {
85+
const main = (initialOptions) => {
86+
const {
87+
el,
88+
value,
89+
initialValue = null,
90+
lineHeight = 1.35,
91+
letterSpacing = 1,
92+
animationDelay = 100,
93+
letterAnimationDelay = 100,
94+
duration = 3000,
95+
} = initialOptions;
9596
const element = select(el);
9697
const computedStyle = window.getComputedStyle(element);
9798
const fontSize = parseInt(computedStyle.fontSize, 10);
@@ -229,5 +230,11 @@ export default ({
229230
transitions.forEach((transition) => transition.resume());
230231
};
231232

232-
return { cancel, pause, resume };
233+
const restart = (options) => {
234+
main({ ...initialOptions, ...options });
235+
};
236+
237+
return { cancel, pause, resume, restart };
233238
};
239+
240+
export default main;

0 commit comments

Comments
 (0)