๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ’ป๋ฐ”๋‹๋ผ JS๋กœ ํฌ๋กฌ ์•ฑ ๋งŒ๋“ค๊ธฐ :#6.0~6.2

change upยท2023๋…„ 6์›” 13์ผ
1
post-thumbnail
  • ์ฒซ ๋ฐฐํฌ์‚ฌ์ดํŠธ..! ์•„๋ž˜์˜ ๋งํฌ๋ฅผ ํด๋ฆญํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
    https://sohwakyeong.github.io/hwakyeong/

  • Html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel = "stylesheet" href="css/app.css">
    <title>Momentum</title>
</head>
<body>
    <form class="hidden" id="login-form">
    <input type="text" />
    <button id="button">Log In</button>
    </form>
    <h2 id ="clock">00:00:00</h2>
    <h1 id="greeting" class="hidden"></h1>
    <div id="quote">
        <span></span>
        <span></span>
    </div>
    <script src="js/clock.js"></script>
    <script src="js/greeting.js"></script>
    <script src="js/quotes.js"></script>
    <script src="js/background.js"></script>
    

</body>
</html>
  • Java Script(Math.random์„ ์ด์šฉํ•ด์„œ array ์•ˆ์— element์— ์ ‘๊ทผํ•˜๊ธฐ.)
/*quotes:๋ช…์–ธ์žํŒ๊ธฐ ๋งŒ๋“ค๊ธฐ.*/
const quotes = [
{
quote: "๋‚˜๋Š” ์‹คํŒจํ•œ ์ ์ด ์—†์–ด. ๋‹จ์ง€ 10,000๋ฒˆ ๋„์ „ํ•ด๋ณด๊ณ  ์–ด๋–ค ๊ฒƒ์ด ๋™์ž‘ํ•˜์ง€ ์•Š๋Š”์ง€ ์•Œ ๋ฟ์ด์ง€.",
author:"<์Šฌ๋žจ๋ฉํฌ>",
},
{
quote: "๋งˆ์Œ์ด ์ง„์ •๋˜๋ฉด ๊ทธ ์†Œ๋ฆฌ๋ฅผ ๋“ค์„ ์ˆ˜ ์žˆ๋‹ค.",
author: "<์„ผ๊ณผ ์น˜ํžˆ๋กœ์˜ ํ–‰๋ฐฉ๋ถˆ๋ช…>",
},
{
quote: "์ƒ์ฒ˜๋Š” ์ƒ์พŒํ•˜๋‹ค. ๊ทธ๊ฑด ๋‚˜๋ฅผ ๊ฐ•ํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ค€๋‹ค",
author: "<๋„๋ผ์—๋ชฝ>",
},
{
quote: "๊ฟˆ์€ ํ”๋“ค๋ฆด ์ˆ˜ ์žˆ์ง€๋งŒ, ํฌ๊ธฐํ•˜๋ฉด ๊ฒฐ์ฝ” ์ด๋ฃจ์–ด์งˆ ์ˆ˜ ์—†๋‹ค.",
author: "<๋„ˆ์˜ ์ด๋ฆ„์€>",
},
{
quote: "์ธ์ƒ์€ ํ•œ ๋ฐฉ! ๋‘ ๋ฒˆ ๋‹ค์‹œ๋Š” ์—†์–ด!",
author: "<์ผ์ƒ>",
},
{
quote: "๋ฏธ๋ž˜์— ๋Œ€ํ•œ ๊ณ ๋ฏผ์€ ์ง€๊ธˆ ์žฌ๋Šฅ์„ ๋ฌป๋Š” ๊ฒƒ์ด๋‹ค.",
author: "<ํ•˜์ดํ>",
},
{
quote: "๋งˆ์Œ์— ๋ถˆ์ด ์žˆ์–ด์•ผ ๋ถˆ์ด ๋ฒˆ์ง€๋Š” ๋ฒ•์ด์ง€!",
author: "<๊ท€๋ฉธ์˜ ์นผ๋‚ >",
},
{
quote: "๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฑด ๋„ค ์•ˆ์˜ ํž˜์ด๋‹ค.",
author: "<๋‚˜๋ฃจํ† >",
},
{
quote: "์šฐ๋ฆฌ๋Š” ํ˜ผ์ž๊ฐ€ ์•„๋‹ˆ์•ผ, ์–ธ์ œ๋‚˜ ์˜†์— ๋„ค๊ฐ€ ์žˆ๋‹ค๋Š” ๊ฑธ ์•Œ์•„.",
author: "<๋ฐ˜์ง€์˜ ์ œ์™•>",
},
{
quote: "๋งˆ์Œ์ด ์›€์ง์—ฌ์•ผ ์šด๋ช…๋„ ์›€์ง์ธ๋‹ค.",
author: "<ํ’€๋ฉ”ํƒˆ ์•Œ์ผ€๋ฏธ์ŠคํŠธ>",
}
]

const quote = document.querySelector('#quote span:first-child');
const author = document.querySelector('#quote span:last-child');

const todaysQuote = quotes[Math.floor(Math.random() * quotes.length)];

quote.innerText = todaysQuote.quote;
author.innerText = todaysQuote.author;
//randomness(๋ฌด์ž‘์œ„์„ฑ): array ์•ˆ์— element์— ์ ‘๊ทผํ•˜๊ธฐ.
//console.log(quotes[10 - 1]); ๋งˆ์ง€๋ง‰ ์š”์†Œ์— ์ ‘๊ทผ .
/*Math.random():between 0 ~ 1.
  Math.round():๋ฐ˜์˜ฌ๋ฆผ
  Math.ceil():์˜ฌ๋ฆผ
  Math.floor():๋‚ด๋ฆผ*/
  • Java Script(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ html์˜ img์š”์†Œ ์ถ”๊ฐ€ํ•˜๊ธฐ)
const images = [
    "pochako1.jpg",
    "pochako2.jpg",
    "pochako3.jpg"
];

const chosenImage = images[Math.floor(Math.random() * images.length)];


const bgImage = document.createElement("img");

bgImage.src = `img/${chosenImage}`;

document.body.appendChild(bgImage);

//append ๋Š” ๊ฐ€์žฅ ๋’ค , prepend๋Š” ๊ฐ€์žฅ ์œ„์— ์˜จ๋‹ค.
  • css
.hidden {
    display: none;
}

#quote span {
    font-weight: bold;
}
#quote {
    position: absolute;
    top: 900px;
    left: 800px;
}

#greeting
{
    position: absolute;
    top: 200px;
    left: 900px;
}

#clock
{
    position: absolute;
    top: 800px;
    left: 950px;
}
//๋”ฐ๋ผ๋งŒ ํ•˜๋‹ˆ , ์žฌ๋ฏธ๊ฐ€ ์—†์–ด์„œ css๋กœ ๊พธ๋ช„๋Š”๋ฐ ๋ณ„๋กœํ•œ๊ฑด ์—†์ง€๋งŒ ๋ฟŒ๋“ฏํ•˜๋‹ค..! 

์˜ค๋Š˜ ๊นƒํ—ˆ๋ธŒ์—์„œ ์ฒ˜์Œ์œผ๋กœ pages๊ธฐ๋Šฅ์„ ์ด์šฉํ•ด์„œ ์‚ฌ์ดํŠธ ๋ฐฐํฌ๋ฅผ ์™„์„ฑํ–ˆ๋‹ค..!
404 ์˜ค๋ฅ˜๋ฅผ ๋งŒ๋‚ฌ์ง€๋งŒ , index.html๋กœ ๋ฐ”๊ฟ”์„œ ๊ทน๋ณต ..!

profile
์ƒˆ์‹น์ด

0๊ฐœ์˜ ๋Œ“๊ธ€