Skip to content

Commit d192f61

Browse files
committed
animation
1 parent 0d76a69 commit d192f61

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

app.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11

22
const APIKey = "93ac677313f294316aab34b8d4ec8917";
33
let activeImgNo = 0;
4-
let backdropImagesArr = [];
54
let slideMovieNames = [];
65
let slideMovieOverview = [];
76

87
const searchBox = document.querySelector(".searchBox__input");
98
const searchBtn = document.querySelector(".searchBox__btn");
109
const resultImg = document.querySelector(".movies");
11-
const backgroundSlide = document.querySelector(".slide");
1210
const imgLeft = document.querySelector(".frontImages__btn--left");
1311
const imgRight = document.querySelector(".frontImages__btn--right");
1412

1513
const placeSlideImages = (data) => {
1614
const slideContainer = document.querySelector(".frontImages");
15+
const backgroundSlide = document.querySelector(".slide");
1716

1817
data.forEach(movie => {
1918
let frontImgUrl = `https://image.tmdb.org/t/p/w342${movie.poster_path}`;
19+
let backImgUrl = `https://image.tmdb.org/t/p/w1280${movie.backdrop_path}`;
2020

21-
backdropImagesArr.push(`https://image.tmdb.org/t/p/w1280${movie.backdrop_path}`);
2221
slideMovieNames.push(movie.title);
2322
slideMovieOverview.push(movie.overview);
2423
// console.log(movie);
@@ -28,22 +27,23 @@ const placeSlideImages = (data) => {
2827
newImg.classList.add("frontImages__img");
2928
newImg.src = `${frontImgUrl}`;
3029
slideContainer.appendChild(newImg);
30+
31+
const newBackImg = document.createElement('img');
32+
newBackImg.classList.add("slide__backImg");
33+
newBackImg.src = `${backImgUrl}`;
34+
backgroundSlide.appendChild(newBackImg);
3135
// console.dir(newImg);
3236
});
3337
}
34-
const setSlides = (data) => {
38+
const setSlides = () => {
3539
const slides = document.querySelectorAll(".frontImages__img");
40+
const backImg = document.querySelectorAll(".slide__backImg");
3641
const title = document.querySelector(".info__title");
3742
const overview = document.querySelector(".info__overview");
3843

3944
slides[activeImgNo].classList.add("active");
45+
backImg[activeImgNo].classList.add('active');
4046

41-
const newImg = document.createElement('img');
42-
newImg.classList.add("slide__backImg");
43-
newImg.src = `${backdropImagesArr[activeImgNo]}`;
44-
backgroundSlide.appendChild(newImg);
45-
46-
// backgroundSlide.style.backgroundImage = `url(${backdropImagesArr[activeImgNo]})`;
4747
title.innerHTML = slideMovieNames[activeImgNo];
4848
overview.innerHTML = slideMovieOverview[activeImgNo];
4949
// console.dir(slides);
@@ -54,7 +54,7 @@ const getSlideImages = async () => {
5454
const res = await axios.get(APIUrl);
5555
// console.log(res.data.results);
5656
placeSlideImages(res.data.results);
57-
setSlides(res.data.results);
57+
setSlides();
5858
}
5959
catch (err) {
6060
console.log(err);
@@ -64,7 +64,11 @@ getSlideImages();
6464

6565
const moveSlideToRight = () => {
6666
const slides = document.querySelectorAll(".frontImages__img");
67+
const backImg = document.querySelectorAll(".slide__backImg");
68+
6769
slides[activeImgNo].classList.remove("active");
70+
backImg[activeImgNo].classList.remove("active");
71+
6872
activeImgNo++;
6973
if (activeImgNo > slides.length - 1) {
7074
activeImgNo = 0;
@@ -73,7 +77,11 @@ const moveSlideToRight = () => {
7377
}
7478
const moveSlideToLeft = () => {
7579
const slides = document.querySelectorAll(".frontImages__img");
80+
const backImg = document.querySelectorAll(".slide__backImg");
81+
7682
slides[activeImgNo].classList.remove("active");
83+
backImg[activeImgNo].classList.remove("active");
84+
7785
activeImgNo--;
7886
if (activeImgNo < 0) {
7987
activeImgNo = slides.length - 1;

css/home.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
position: absolute;
1616
background-color: rgba(0, 0, 0, .5);
1717
z-index: 2;
18-
animation: Opacity .4s ease-in-out;
18+
/* animation: Opacity .4s ease-in-out; */
1919
}
2020

2121
.slide__backImg {
@@ -26,7 +26,9 @@
2626
height: 100%;
2727
object-fit: cover;
2828
object-position: top;
29-
animation: Opacity .8s ease-in-out;
29+
opacity: 0;
30+
transition: .6s ease-in-out;
31+
/* animation: Opacity .8s ease-in-out; */
3032
}
3133

3234
.frontImages {

0 commit comments

Comments
 (0)