console
<script>
var inputstr = "一";
var options = {
width: 300,
height: 300,
padding: 5,
showOutline:true,
strokeAnimationSpeed:11 ,
delayBetweenStrokes:2,
radicalColor: '#168F16',
showCharacter: false,
delayBetweenLoops:100,
showHintAfterMisses:2,
highlightOnComplete:false,
};
let hw = HanziWriter.create('grid-background-target', inputstr, options);
function hwanimate() {
inputstr = document.getElementById("inputstr").value;
if(inputstr && inputstr.trim().length>0)
{
hw.setCharacter(inputstr.substr(0, 1).trim());
inputstr = inputstr.substring(1)
}
hwtest()
};
hwtest()
function hwtest() {
var phw = new Promise((res, rej)=>{
hw.quiz({
onMistake: function (strokeData) { },
onCorrectStroke: function (strokeData) { },
onComplete: function (summaryData) {
let arrays = ["三", "川", "土", "丰", "十", "士", "田", "干", "千", "二", "生", "日", "曰", "口"]
let nextch = "";
if (inputstr.length > 0) {
nextch = inputstr.substr(0, 1);
inputstr = inputstr.substring(1);
} else { nextch = arrays[Math.floor(Math.random() * arrays.length)]; }
res(nextch);
}
});
})
phw.then((data)=>{hw.setCharacter(data); hwtest()}, ()=>{console.log(22)});
var VERSION = '2.0';
var getCharDataUrl = function getCharDataUrl(char) {
return 'https://cdn.jsdelivr.net/npm/hanzi-writer-data@' + VERSION + '/' + char + '.json';
};
}
</script>
// 问题输入汉字不显示 ,跨域? //
<head>
<script src="./src/chwriter.js"></script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
</head>
<body>
输入汉字进行练习:<input type="text" id="inputstr"/>
<button onclick="hwanimate()">动画</button>
<div id="character-target-div"></div>
<svg width="300" height="300" style="border: 1px solid rgb(221,221,221);" id="grid-background-target">
<line x1="0" y1="0" x2="300" y2="300" stroke="#DDD" />
<line x1="300" y1="0" x2="0" y2="300" stroke="#DDD" />
<line x1="150" y1="0" x2="150" y2="300" stroke="#DDD" />
<line x1="0" y1="150" x2="300" y2="150" stroke="#DDD" />
</svg>
</body>