λ©ν°λ―Έλμ΄ νκ·Έ
HTMLμμ μ€λμ€, λΉλμ€, κ·Έλν½ λ± λ€μν λ©ν°λ―Έλμ΄ μ½ν
μΈ λ₯Ό μΉ νμ΄μ§μ μ½μ
νκ±°λ μ μ΄ν μ μλ νκ·Έλ₯Ό λ§ν©λλ€.
β’
audio
β’
video
β’
iframe
β’
canvas
audio
μΉ νμ΄μ§μμ μ€λμ€ νμΌμ μ¬μν μ μλ νκ·Έμ
λλ€.
νκ·Έ | μμ± | μ€λͺ
| μμ |
<audio> | src | μ€λμ€ νμΌμ URLμ μ§μ | <audio src="sound.mp3"></audio> |
controls | κΈ°λ³Έ μ€λμ€ μ»¨νΈλ‘€(μ¬μ, μΌμ μ μ§ λ±)μ νμ | <audio controls></audio> | |
autoplay | νμ΄μ§ λ‘λ μ μλμΌλ‘ μ€λμ€λ₯Ό μ¬μ | <audio src="sound.mp3" autoplay></audio> | |
loop | μ€λμ€κ° λλ ν μλμΌλ‘ λ€μ μμ | <audio src="sound.mp3" loop></audio> | |
muted | μ€λμ€λ₯Ό μμκ±° μνλ‘ μ€μ | <audio src="sound.mp3" muted></audio> | |
preload | νμ΄μ§ λ‘λ μ μ€λμ€λ₯Ό 미리 λ‘λν μ§ μ¬λΆλ₯Ό μ€μ (auto, metadata, none) | <audio src="sound.mp3" preload="auto"></audio> |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>μ€λμ€ νκ·Έ</title>
</head>
<body>
<!--
audio νκ·Έ μμ±
- autoplay : μλμ¬μ
- controls : μ€λμ€ μ¬μ/λ³Όλ₯¨ 컨νΈλ‘€ νμ
- loop : λ°λ³΅μ¬μ
- preload : μ€λμ€ νμΌ λ―Έλ¦¬ λ€μ΄λ‘λ
- src : μ¬μν μ€λμ€ νμΌ κ²½λ‘
- volume : μ¬μ λ³Όλ₯¨ ν¬κΈ° ( 0.0~1.0 )
- audio format(νμΌ ν¬λ§·) : mp3, ogg, wav
- MIME type(νμΌ νμ) : audio/mp3, audio/ogg, audio/wav
-->
<h1>audio νκ·Έ</h1>
<audio src="audio/bgm.mp3" controls></audio>
<h1>νμ₯μ νΈν</h1>
<audio controls autoplay>
<source src="audio/bgm.mp3" type="audio/mp3">
<source src="audio/bgm.ogg" type="audio/ogg">
<source src="audio/bgm.wav" type="audio/wav">
</audio>
<!--
source
: λΈλΌμ°μ λ§λ€ μ§μνλ μ€λμ€ νμΌ νμμ νΈνμμΌμ£ΌκΈ° μν νκ·Έ
-->
</body>
</html>
HTML
볡μ¬
video
μΉ νμ΄μ§μμ λΉλμ€ νμΌμ μ¬μν μ μλ νκ·Έμ
λλ€.
νκ·Έ | μμ± | μ€λͺ
| μμ |
<video> | src | λΉλμ€ νμΌμ URLμ μ§μ | <video src="movie.mp4"></video> |
controls | κΈ°λ³Έ λΉλμ€ μ»¨νΈλ‘€(μ¬μ, μΌμ μ μ§ λ±)μ νμ | <video controls></video> | |
autoplay | νμ΄μ§ λ‘λ μ μλμΌλ‘ λΉλμ€λ₯Ό μ¬μ | <video src="movie.mp4" autoplay></video> | |
loop | λΉλμ€κ° λλ ν μλμΌλ‘ λ€μ μμ | <video src="movie.mp4" loop></video> | |
muted | λΉλμ€μ μ리λ₯Ό μμκ±° μνλ‘ μ€μ | <video src="movie.mp4" muted></video> | |
preload | νμ΄μ§ λ‘λ μ λΉλμ€λ₯Ό 미리 λ‘λν μ§ μ¬λΆλ₯Ό μ€μ (auto, metadata, none) | <video src="movie.mp4" preload="auto"></video> | |
width | λΉλμ€μ κ°λ‘ ν¬κΈ°λ₯Ό μ€μ | <video src="movie.mp4" width="640"></video> | |
height | λΉλμ€μ μΈλ‘ ν¬κΈ°λ₯Ό μ€μ | <video src="movie.mp4" height="360"></video> |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>λΉλμ€ νκ·Έ</title>
</head>
<body>
<!--
video νκ·Έ μμ±
- autoplay : μλμ¬μ
- controls : μ€λμ€ μ¬μ/λ³Όλ₯¨ 컨νΈλ‘€ νμ
- loop : λ°λ³΅μ¬μ
- preload : νμΌ λ―Έλ¦¬ λ€μ΄λ‘λ
- src : μ¬μν μ€λμ€ νμΌ κ²½λ‘
- volume : μ¬μ λ³Όλ₯¨ ν¬κΈ° ( 0.0~1.0 )
- poster : μΈλ€μΌ μ΄λ―Έμ§
- muted : λΉλμ€μ μ€λμ€ μμκ±°
- width/height : λΉλμ€ κ°λ‘ μΈλ‘ μ¬μ΄μ¦
- video format(νμΌν¬λ§·) : mp4, webm, ogg
- MIME type (νμΌνμ) : video/mp4, video/webm, video/ogg
-->
<h1>video νκ·Έ</h1>
<video src="video/video.mp4" autoplay controls
width="1024" height="768"></video>
<h1>νμ₯μ νΈν</h1>
<video width="1024" height="768" controls>
<source src="video/video.mp4" type="video/mp4">
<source src="video/video.ogg" type="video/ogg">
<source src="video/video.webm" type="video/webm">
</video>
<h1>μΈλ€μΌ</h1>
<video src="video/video.mp4" controls width="1024" height="768"
poster="img/poster.png"></video>
<div style="height: 500px;"></div>
</body>
</html>
HTML
볡μ¬
iframe
λ€λ₯Έ μΉ νμ΄μ§λ₯Ό νμ¬ νμ΄μ§ λ΄μ μ½μ
ν μ μλ νκ·Έμ
λλ€.
νκ·Έ | μμ± | μ€λͺ
| μμ |
<iframe> | src | iframeμ μ½ν
μΈ λ₯Ό λ‘λν URLμ μ§μ | <iframe src="https://example.com"></iframe> |
width | iframeμ κ°λ‘ ν¬κΈ°λ₯Ό μ€μ | <iframe src="https://example.com" width="600"></iframe> | |
height | iframeμ μΈλ‘ ν¬κΈ°λ₯Ό μ€μ | <iframe src="https://example.com" height="400"></iframe> | |
title | iframeμ μ½ν
μΈ λ₯Ό μ€λͺ
νλ μ λͺ©μ μ€μ | <iframe src="https://example.com" title="Description"></iframe> | |
frameborder | iframeμ ν
λ리 μ€μ (0 λλ 1) | <iframe src="https://example.com" frameborder="0"></iframe> | |
allowfullscreen | iframeμ μ½ν
μΈ λ₯Ό μ 체 νλ©΄ λͺ¨λλ‘ νμν μ μκ² νμ© | <iframe src="https://example.com" allowfullscreen></iframe> |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>iframe</title>
</head>
<body>
<!--
iframe (inline frame)
: μΉ νμ΄μ§ μμμ λ€λ₯Έ μΉ νμ΄μ§λ₯Ό νμνλ νκ·Έ
- name μμ±μ μ§μ νλ©΄ target νλ μμΌλ‘ μ¬μ©ν μ μλ€
- naver, google λ± μΌλΆ μ¬μ΄νΈμμλ iframe μ ν΅ν΄ μ κ·Όμ λ§κ³ μλ€.
-->
<h1>λ΄λΆ νμ΄μ§ λ° μΈλΆ νμ΄μ§ νμνκΈ°</h1>
<iframe src="03_inner.html" width="400" height="240"></iframe>
<iframe src="http://www.tcpschool.com" width="400" height="240"></iframe>
<hr>
<h3>target νλ μμΌλ‘ νμνκΈ°</h3>
<iframe src="" name="frame1" width="400" height="240"></iframe>
<p>
<a href="http://typingclub.com" target="frame1">μν μ¬μ΄νΈ</a>
</p>
<iframe src="" name="frame2" width="400" height="240"></iframe>
<p>
<a href="http://hancomtyping.com" target="frame2">νν μ¬μ΄νΈ</a>
</p>
<h3>Youtube λμμ νμνκΈ°</h3>
<iframe width="560" height="315" src="https://www.youtube.com/embed/zsA3gixXHNk?si=9_tpK6zy8vjqDHIW"
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
<div style="height: 500px;"></div>
</body>
</html>
HTML
볡μ¬
canvas
κ·Έλν½μ 그리거λ μ λλ©μ΄μ
μ λ§λ€ μ μλ μμμ μ 곡ν©λλ€.
JavaScriptμ ν¨κ» μ¬μ©λμ΄ λμ μΈ κ·Έλν½μ μμ±ν μ μμ΅λλ€.
νκ·Έ | μμ± | μ€λͺ
| μμ |
<canvas> | width | μΊλ²μ€μ κ°λ‘ ν¬κΈ°λ₯Ό μ€μ | <canvas width="500"></canvas> |
height | μΊλ²μ€μ μΈλ‘ ν¬κΈ°λ₯Ό μ€μ | <canvas height="300"></canvas> | |
id | μΊλ²μ€ μμμ μλ³μ | <canvas id="myCanvas"></canvas> | |
style | μΊλ²μ€μ CSS μ€νμΌμ μ€μ | <canvas style="border:1px solid #000;"></canvas> |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>λΈλ¬μλ‘ κ·Έλ¦Ό 그리기</title>
<style>
canvas {
border: 1px solid black;
display: block;
margin: 0 auto;
background-color: #f0f0f0;
}
.controls {
text-align: center;
margin: 20px;
}
button {
margin: 0 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="controls">
<button id="clearBtn">μ 체 μ§μ°κΈ°</button>
<button id="saveBtn">κ·Έλ¦ΌμΌλ‘ μ μ₯νκΈ°</button>
</div>
<canvas id="myCanvas" width="800" height="600"></canvas>
<script>
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
let drawing = false;
// λ§μ°μ€ λ€μ΄ μ΄λ²€νΈ νΈλ€λ¬
canvas.addEventListener('mousedown', (e) => {
drawing = true;
ctx.beginPath();
ctx.moveTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop);
});
// λ§μ°μ€ μ
μ΄λ²€νΈ νΈλ€λ¬
canvas.addEventListener('mouseup', () => {
drawing = false;
});
// λ§μ°μ€ μ΄λ μ΄λ²€νΈ νΈλ€λ¬
canvas.addEventListener('mousemove', (e) => {
if (drawing) {
ctx.lineTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop);
ctx.strokeStyle = 'black'; // μ μμ
ctx.lineWidth = 5; // μ λκ»
ctx.lineCap = 'round'; // μ λ λͺ¨μ
ctx.stroke();
}
});
// λ§μ°μ€ λ λκΈ° μ΄λ²€νΈ νΈλ€λ¬
canvas.addEventListener('mouseleave', () => {
if (drawing) {
drawing = false;
}
});
// μ 체 μ§μ°κΈ° λ²νΌ μ΄λ²€νΈ νΈλ€λ¬
document.getElementById('clearBtn').addEventListener('click', () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
});
// κ·Έλ¦ΌμΌλ‘ μ μ₯νκΈ° λ²νΌ μ΄λ²€νΈ νΈλ€λ¬
document.getElementById('saveBtn').addEventListener('click', () => {
const link = document.createElement('a');
link.href = canvas.toDataURL('image/png');
link.download = 'drawing.png';
link.click();
});
</script>
</body>
</html>
HTML
볡μ¬