jQuery 자동 사진 생성

삼전·2023년 5월 31일
0

jQuery

목록 보기
11/15
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<!-- CDN으로 jQuery 라이브러리 연결하기 - https://cdnjs.com/libraries/jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
</head>
<style>
	img{width:100px; height:100px;}
</style>
<body>
	<img src="../img/swisda.jpg" />
	<script>
		$(function(){
			//trigger: 자동으로 이벤트를 발생시킨다.
			var imgTag = "<img src='../img/swisda.jpg' />"
			
			//1.이벤트 click, 클릭시 바디 태그 안에 사진 생성 
			$("img").first().on('click', function(){
				$('body').append(imgTag)
			});
			//2.trigger를 이용하여 click이벤트를 1초에 한번식 발생시킨다.
			setInterval(function(){
				$('img:first').trigger('click')
			},1000)
		})
	</script>
</body>
</html>

결과

profile
풀스택eDot

0개의 댓글