Closed rodrigomorales1 closed 1 year ago
The following does the job.
<head>
<script src="https://cdn.jsdelivr.net/npm/hanzi-writer@3.2/dist/hanzi-writer.min.js"></script>
</head>
<body>
<div id="character-target-div"></div>
<script>
var writer = HanziWriter.create('character-target-div', '迄', {
width: 100,
height: 100,
padding: 5,
});
function foo() {
writer.animateStroke(2, {
onComplete: foo
})
}
foo()
</script>
</body>
Alternatively, you can also set a delay between the animation of that specific stroke.
<head>
<script src="https://cdn.jsdelivr.net/npm/hanzi-writer@3.2/dist/hanzi-writer.min.js"></script>
</head>
<body>
<div id="character-target-div"></div>
<script>
var writer = HanziWriter.create('character-target-div', '迄', {
width: 100,
height: 100,
padding: 5,
});
var delayBetweenAnimations = 1000;
function foo() {
writer.animateStroke(2, {
onComplete: function() {
setTimeout(
function() {
foo()
}, delayBetweenAnimations);
}
})
}
foo()
</script>
</body>
What I want to do
I want to infinite loop the 3rd stroke of the character 迄 (i.e. the stroke "乙" that is below "𠂉").
What I've tried
I'm aware of the function
animateStroke
. By using this function, I can animate the stroke "乙" of the character "迄" (see minimal working example below)I'm also aware that the function
animateStroke
accepts anonComplete
callback. By using this callback, I was able to repeat the desired stroke a specific number times (not infinite repetitions). See minimal working example below.As you can see above, by using nested
onComplete
, the stroke is repeated 3 times. However, as I mentioned, I want the stroke to be infinitely repeated.