IT Study/Web

[JavaScript] setInterval 응용 예제

도뿌리 2018. 8. 6. 14:39

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 
<h1>여기는 index3.html입니다.</h1>
 
<form name="myForm">
    <input type="text" size="30" name="myFormMsg">
</form>
 
<script type="text/javascript">
myMsg = "환영합니다 어서 오십시오";
myCnt = 0;
 
function myfunc() {
    document.myForm.myFormMsg.value = myMsg.substring(0,myCnt) + "_";
    
    myCnt = ( myCnt == myMsg.length) ? 0 : ++myCnt;
}
 
setInterval("myfunc()",500);
 
</script>
</body>
</html>
cs

'환영합니다 어서 오십시오'

문자열이 0.5초마다 한글자씩 출력된다(애니메이션 효과)