๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Javascript/Effect

Game Effect ๊ฒŒ์ž„ ํšจ๊ณผ 01 : jquery ์ด๋ฏธ์ง€ ๋“œ๋ž˜๊ทธ / JS ๋‚ ์งœ์™€ ์‹œ๊ฐ„ & ์šด์˜์ฒด์ œ์™€ ํ™”๋ฉดํฌ๊ธฐ ์ •๋ณด ๊ตฌํ˜„

by oranssy 2022. 10. 20.
728x90
๋ฐ˜์‘ํ˜•

โญ๏ธ Game Effect ๊ฒŒ์ž„ ํšจ๊ณผ 01 : jquery ์ด๋ฏธ์ง€ ๋“œ๋ž˜๊ทธ / JS ๋‚ ์งœ์™€ ์‹œ๊ฐ„ & ์šด์˜์ฒด์ œ์™€ ํ™”๋ฉดํฌ๊ธฐ ์ •๋ณด ๊ตฌํ˜„ โญ๏ธ


01. jquery ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€ ๋“œ๋ž˜๊ทธ ํšจ๊ณผ ๊ตฌํ˜„ํ•˜๊ธฐ

๐ŸงŠ jquery ์‚ฌ์ดํŠธ์—์„œ ๋“œ๋ž˜๊ทธ ํšจ๊ณผ์˜ ์ฃผ์†Œ๋ฅผ ๊ฐ€์ ธ์™€ script ์— ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. ๐ŸงŠ ๋งˆ์šฐ์Šค ์ปค์„œ ๋ชจ์–‘์„ ๋”ฐ๋กœ ์„ค์ •ํ•ด์ฃผ์—ˆ๋‹ค๋ฉด, ์ด๋ฏธ์ง€๋ฅผ ๋“œ๋ž˜๊ทธํ•  ๋•Œ๋„ ๋ชจ์–‘์ด ์œ ์ง€๋˜๋„๋ก script ์— ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

[1] ๋“œ๋ž˜๊ทธ ํšจ๊ณผ - jquery ์ฃผ์†Œ ๋„ฃ๊ธฐ

<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>

[2] ๋งˆ์šฐ์Šค ์ปค์„œ ๋ชจ์–‘ ์œ ์ง€๋ฅผ ์œ„ํ•œ ํ•จ์ˆ˜ ์ถ”๊ฐ€ํ•˜๊ธฐ

$( ".์‚ฝ์ž…ํ•œ ์ด๋ฏธ์ง€ ํด๋ž˜์Šค๋ช…" ).draggable({
    drag: function(){
        $(".๋งˆ์šฐ์Šค ์ปค์„œ ํด๋ž˜์Šค๋ช…").style
    },
});

$( ".icon" ).draggable({
drag: function(){
$(".mouse__cursor").style
},
});

02. JS ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋‚ ์งœ์™€ ์‹œ๊ฐ„ ๊ตฌํ˜„ํ•˜๊ธฐ

๐ŸงŠ html ์˜ header ๋ถ€๋ถ„์— ๋‚ ์งœ์™€ ์‹œ๊ฐ„ ์ •๋ณด๋ฅผ ๋„์šธ div ํƒœ๊ทธ๋ฅผ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค. ๐ŸงŠ script ์— ๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ๊ณ„์‚ฐํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

[1] div ํƒœ๊ทธ ๋งŒ๋“ค๊ธฐ (html)

div ํƒœ๊ทธ๋ฅผ ๋งŒ๋“ค๊ณ , css ์™€ JS ์˜ ๊ฒฝ๋กœ ์„ค์ •์„ ์œ„ํ•ด class ๋กœ ์ด๋ฆ„์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

<header id="header">
<h1>
<div class="head1"></div> // ์•„์ด์ฝ˜์„ ๋„ฃ์„ div
Oranssy's Playground // ํŽ˜์ด์ง€ ์ œ๋ชฉ
<div class="head2"></div> // ์•„์ด์ฝ˜์„ ๋„ฃ์„ div
</h1>
<div class="time"></div> // ๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ๋‚˜ํƒ€๋‚ผ div
</header>
<!-- //header -->

[2] ๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ๊ณ„์‚ฐํ•˜๋Š” ํ•จ์ˆ˜ ์ž‘์„ฑํ•˜๊ธฐ

// ํ—ค๋”์˜ ์‹œ๊ณ„
function printTime(){
const clock = document.querySelector(".time");
const now = new Date();
// clock.innerText = now; // ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„ ๋ฐ์ดํ„ฐ๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ํ™•์ธ
let hr = now.getHours(); // ์‹œ (0์—์„œ 23 ์‚ฌ์ด์˜ ์ •์ˆ˜)
if (hr < 10) hr = '0' + hr; // ์ผ์˜ ์ž๋ฆฌ ์ˆซ์ž ์•ž์— 0 ๋ถ™์ด๊ธฐ
// if (hr > 12) hr = hr - 12; // '16์‹œ' ๋กœ ๋‚˜์˜ค์ง€ ์•Š๊ณ  4์‹œ๋กœ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋„๋ก
let min = now.getMinutes(); // ๋ถ„ (0์—์„œ 59 ์‚ฌ์ด์˜ ์ •์ˆ˜)
if (min < 10) min = '0' + min;
let sec = now.getSeconds(); // ์ดˆ (0์—์„œ 59 ์‚ฌ์ด์˜ ์ •์ˆ˜)
if (sec < 10) sec = '0' + sec;
let month = now.getMonth() +1; // ์›” (0์—์„œ 11 ์‚ฌ์ด์˜ ์ •์ˆ˜. 0์€ 1์›”, 1์€ 2์›”... ์„ ๋‚˜ํƒ€๋ƒ„) ์ˆซ์ž๋กœ ํ‘œ์‹œ๋˜๋ฏ€๋กœ ์›”์—๋Š” +1 ์„ ํ•ด์ค˜์•ผ ํ•จ.
if (month < 10) month = '0' + month;
// getFullYear() -> ๋‚ ์งœ์˜ ์—ฐ๋„์— ํ•ด๋‹นํ•˜๋Š” ์ˆซ์ž
// getDate() -> ์ผ (1 ์ด์ƒ 31 ์ดํ•˜์˜ ์ •์ˆ˜)
// const nowTime = "๐Ÿ“… " + now.getFullYear() + "๋…„ " + (now.getMonth() +1) + "์›” " + now.getDate() + "์ผ โฐ " + now.getHours() + "์‹œ " + now.getMinutes() + "๋ถ„ " + now.getSeconds() + "์ดˆ";
const nowTime = "๐Ÿ“… " + now.getFullYear() + " . " + (now.getMonth() +1) + " . " + now.getDate() + " ____ โฐ " + hr + " : " + min + " : " + sec + " ";
clock.innerText = nowTime;
setTimeout("printTime()", 1000) // 1000 = 1์ดˆ ๊ฐ„๊ฒฉ์œผ๋กœ
}
// ์œˆ๋„์šฐ๊ฐ€ ์‹œ์ž‘ํ•˜์ž๋งˆ์ž, ์ž‘๋™ํ•˜์‹œ์˜ค. (๋งจ ์•„๋ž˜์— ์žˆ์–ด์•ผ ํ•จ)
window.onload = function(){
printTime();
}

03. JS ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์‚ฌ์šฉ๊ธฐ๊ธฐ์˜ ์ •๋ณด(์šด์˜์ฒด์ œ, ํ™”๋ฉดํฌ๊ธฐ) ๊ตฌํ˜„ํ•˜๊ธฐ

๐ŸงŠ html ์˜ footer ์— ์‚ฌ์šฉ๊ธฐ๊ธฐ ์ •๋ณด๋ฅผ ๋„์šธ div ํƒœ๊ทธ๋ฅผ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค. ๐ŸงŠ script ์— ์‚ฌ์šฉ๊ธฐ๊ธฐ์˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

[1] div ํƒœ๊ทธ ๋งŒ๋“ค๊ธฐ (html)

div ํƒœ๊ทธ๋ฅผ ๋งŒ๋“ค๊ณ , css ๊ฒฝ๋กœ ์„ค์ •์„ ์œ„ํ•ด class ๋กœ ์ด๋ฆ„์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

<footer id="footer">
<div class="foot1"></div>
<div class="agent"></div>
</footer>

[2] ์‚ฌ์šฉ๊ธฐ๊ธฐ์˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜ ์ž‘์„ฑํ•˜๊ธฐ

// ํ‘ธํ„ฐ์˜ ์‚ฌ์šฉ๊ธฐ๊ธฐ ์ •๋ณด
function printAgent(){
const agent = document.querySelector(".agent");
const os = navigator.userAgent.toLocaleLowerCase(); // ์‚ฌ์šฉ์ž์˜ ๊ธฐ๊ธฐ ์ •๋ณด(์šด์˜์ฒด์ œ, ํ™”๋ฉด ํฌ๊ธฐ)์„ ๊ฐ€์ง€๊ณ  ์˜ด
// agent.innerText = os; // ๊ธฐ๊ธฐ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์˜ค๋Š”์ง€ ํ™•์ธ
// indexOf (๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ, ์ธ๋ฑ์Šค๊ฐ€ ๋ฐฐ์—ด์˜ ๊ธธ์ด๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์€ ๊ฒฝ์šฐ -1 ์ด ๋ฐ˜ํ™˜๋˜๋ฏ€๋กœ ๋ฐฐ์—ด์ด ๊ฒ€์ƒ‰๋˜์ง€ ์•Š์Œ)
if(os.indexOf("window") >= 0){ // ๋ฐฐ์—ด์ด ๊ฒ€์ƒ‰๋˜๋‹ˆ ์•Š๋Š” ๊ฒฝ์šฐ์ธ -1 ์„ ์ œ์™ธ -> 0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์„ ๋•Œ.
agent.innerText = "ํ˜„์žฌ ์œˆ๋„์šฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ณ , ํ™”๋ฉด ํฌ๊ธฐ๋Š” " + screen.width + " * " + screen.height + " ์ž…๋‹ˆ๋‹ค."
document.querySelector("body").classList.add("window");
} else if(os.indexOf("macintosh") >= 0) {
agent.innerText = "ํ˜„์žฌ ๋งฅ์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ณ , ํ™”๋ฉด ํฌ๊ธฐ๋Š” " + screen.width + " * " + screen.height + " ์ž…๋‹ˆ๋‹ค."
document.querySelector("body").classList.add("macintosh");
} else if(os.indexOf("iphone") >= 0) {
agent.innerText = "ํ˜„์žฌ ์•„์ดํฐ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ณ , ํ™”๋ฉด ํฌ๊ธฐ๋Š” " + screen.width + " * " + screen.height + " ์ž…๋‹ˆ๋‹ค."
document.querySelector("body").classList.add("iphone");
} else if(os.indexOf("android") >= 0) {
agent.innerText = "ํ˜„์žฌ ์•ˆ๋“œ๋กœ์ด๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ณ , ํ™”๋ฉด ํฌ๊ธฐ๋Š” " + screen.width + " * " + screen.height + " ์ž…๋‹ˆ๋‹ค."
document.querySelector("body").classList.add("android");
}
}
// ์œˆ๋„์šฐ๊ฐ€ ์‹œ์ž‘ํ•˜์ž๋งˆ์ž, ์ž‘๋™ํ•˜์‹œ์˜ค. (๋งจ ์•„๋ž˜์— ์žˆ์–ด์•ผ ํ•จ)
window.onload = function(){
printAgent();
}

04. ๊ฒฐ๊ณผ๋ณด๊ธฐ

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€