내가 가진 텍스트 영역에 주어진 문자열을 추가하고 싶습니다. 누군가가 텍스처에 타이핑하는 것처럼 보이는 방식으로 텍스트를 추가하고 싶습니다. 왜냐하면 6 초 동안 배경에서 동일한 내용을 말하는 음성이 있기 때문입니다. 작성됩니다.
<textarea id='typeable' style='font-size:18px;background:#F8E71C'></textarea>
<script>
function addText(event) {
document.getElementById("typeable").value += "Hello welcome to the new world of javascript"
}
</script>
내가 어떻게 할 수 있니
카운트 문자 수 문장의를 한 다음 계산 각 문자에 대한 시간을 없음으로 총 시간을 나누어. 문자 수를 입력 한 다음 시간 간격을 호출하고 모든 문자가 인쇄 될 때까지 실행합니다.
그래도 각 문자를 인쇄하는 데 걸리는 시간을 결정하고 필요에 따라 수정할 수 있습니다. 시간은 밀리 초 단위입니다.
var chars = "Hello welcome to the new world of javascript".split("");
var textarea = document.querySelector('textarea');
var total_time=6000;
var index = 0;
var time_per_char = total_time/chars.length;
var t = setInterval(function(){
textarea.value += chars[index];
index++;
if (index === chars.length){
clearInterval(t);
}
},time_per_char);
<textarea style="width:100%;background:#E1ECF4">
</textarea>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다