<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel = "stylesheet" href = "../css/mystyle.css" type="text/css">
<link rel="shortcut icon" type="image/x-icon" href="../images/Koala.jpg" >
<script>
str = ["좋은아침", "졸린오후", "신나는 저녁", "행복한 하루", "맛있는 점심"];
function addProc() {
rnd = parseInt(Math.random() * str.length);
text = document.createTextNode(str[rnd]);
ptag = document.createElement('p');
ptag.appendChild(text);
document.getElementById('result1').appendChild(ptag);
}
function delProc() {
parent = document.getElementById('result1');
child = parent.lastChild;
parent.removeChild(child);
}
function proc2() {
random = parseInt(Math.random() * str.length);
text = document.createTextNode(str[random]);
bttag = document.createElement('input');
bttag.type = "button";
bttag.value = "삭제";
bttag.onclick = function() {
parent = this.parentNode.remove();
};
ptag = document.createElement('p');
ptag.appendChild(text);
ptag.appendChild(bttag);
document.getElementById('result2').appendChild(ptag);
}
index = 0;
function start(vt){
gvt = vt;
vt.style.display = "none";
parent = document.getElementById('result3');
child2 = parent.getElementsByTagName('img')[index];
console.log(parent.getElementsByTagName('img'));
console.log(parent);
child2.style.border = "none";
idx = setInterval(function(){
child = parent.firstChild;
document.getElementById('result3').appendChild(child);
}, 300)
}
function stop(){
clearInterval(idx);
index = parseInt(Math.random() * 5);
parent = document.getElementById('result3');
child = parent.getElementsByTagName('img')[index];
child.style.border = "5px solid red";
gvt.style.display = "inline";
}
</script>
<style type="text/css">
img{
width : 100px;
height : 100px;
}
</style>
</head>
<body>
<div class="box">
추가버튼 클릭 시<br>
랜덤으로 발생되는 문자를 result1에 출력<br>
<br>
삭제버튼 클릭 시<br>
추가된 문자를 차례대로 삭제<br>
<br>
<button type="button" onclick="addProc()">추가</button>
<button type="button" onclick="delProc()">삭제</button>
<div id="result1"></div>
</div>
<div class="box">
추가삭제버튼 클릭 - 이미지 회전<br>
랜덤으로 발생되는 문자와 삭제버튼을 생성하여 result2에 출력<br>
<br>
<button type="button" onclick="proc2()">추가삭제</button>
<div id="result2"></div>
</div>
<div class = "box">
시작버튼 클릭 시 이미지 회전<br>
첫번째 이미지를 선택하여 appendChild()로 div의 맨 마지막에 추가된다<br>
첫번째 이미지는 잘라내기 붙여넣기와 같은 이동의 효과가 나타난다<br>
시작버튼은 사라진다
종료버튼클릭하면 다시 시작 버튼이 나타나야 되고
당첨을 표시한다
다시 시작버튼 클릭 시 당첨표시를 클리어 후 실행 한다
<br>
<button type = "button" onclick="start(this)">시작</button>
<button type = "button" onclick="stop()">종료</button>
<div id = "result3">
<img src="../images/옷1.jpg" alt="옷1.jpg">
<img src="../images/옷2.jpg" alt="옷2.jpg">
<img src="../images/음악1.jpg" alt="음악1.jpg">
<img src="../images/핫초코.jpg" alt="핫초코.jpg">
<img src="../images/풍차.jpg" alt="풍차.jpg">
</div>
</div>
</body>
</html>