
โญ๏ธ 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(); }
๋๊ธ