HTML Layout 세팅
<header>
<div class="leftMenu">
<h1 id="cineDocsTitle">CineDocs</h1>
</div>
<div class="rightMenu">
<form>
<input type="text" id="search_text" placeholder="Search" autofocus />
<button type="button" id="search_btn">검색</button>
</form>
</div>
</header>
<main>
<div class="movie_list"></div>
</main>
CSS Layout 세팅
header {
display: flex;
justify-content: space-around;
align-items: center;
background-color: lightblue;
border-radius: 5px;
box-shadow: 0px 0px 3px 0px lightskyblue;
}
h1 {
letter-spacing: 3px;
font-family: "Courier New", Courier, monospace;
}
.movie_card, .movie_content, .movie_img {
padding: 30px;
}
.movie_card {
display: flex;
margin: 20px auto;
background-color: whitesmoke;
border: 1px solid lightgray;
border-radius: 5px;
box-shadow: 0px 0px 3px 0px lightblue;
}
JSON 데이터 가공
const movie_list = document.querySelector(".movie_list");
fetch(url, options)
.then((res) => res.json())
.then((data) => {
const movie_data = data["results"];
const movie_result = movie_data.map((movie) =>{
let movie_html = `
<div class="movie_card">
<div class="movie_content">
<h2>${movie.title} (${movie.original_title})</h2>
<p><strong>개봉일</strong> : ${movie.release_date} / <strong>평점</strong> : ${movie.vote_average}</p>
<p>${movie.overview}</p>
</div>
<div class="movie_img">
<img src="https://image.tmdb.org/t/p/w185${movie.poster_path}" />
</div>
</div>`;
return movie_html;
});
movie_result.forEach((movie) => {
movie_list.innerHTML += movie;
});
})
.catch((err) => console.log(err));
결과 화면