1
1
2
2
const APIKey = "93ac677313f294316aab34b8d4ec8917" ;
3
3
let activeImgNo = 0 ;
4
- let backdropImagesArr = [ ] ;
5
4
let slideMovieNames = [ ] ;
6
5
let slideMovieOverview = [ ] ;
7
6
8
7
const searchBox = document . querySelector ( ".searchBox__input" ) ;
9
8
const searchBtn = document . querySelector ( ".searchBox__btn" ) ;
10
9
const resultImg = document . querySelector ( ".movies" ) ;
11
- const backgroundSlide = document . querySelector ( ".slide" ) ;
12
10
const imgLeft = document . querySelector ( ".frontImages__btn--left" ) ;
13
11
const imgRight = document . querySelector ( ".frontImages__btn--right" ) ;
14
12
15
13
const placeSlideImages = ( data ) => {
16
14
const slideContainer = document . querySelector ( ".frontImages" ) ;
15
+ const backgroundSlide = document . querySelector ( ".slide" ) ;
17
16
18
17
data . forEach ( movie => {
19
18
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 } ` ;
20
20
21
- backdropImagesArr . push ( `https://image.tmdb.org/t/p/w1280${ movie . backdrop_path } ` ) ;
22
21
slideMovieNames . push ( movie . title ) ;
23
22
slideMovieOverview . push ( movie . overview ) ;
24
23
// console.log(movie);
@@ -28,22 +27,23 @@ const placeSlideImages = (data) => {
28
27
newImg . classList . add ( "frontImages__img" ) ;
29
28
newImg . src = `${ frontImgUrl } ` ;
30
29
slideContainer . appendChild ( newImg ) ;
30
+
31
+ const newBackImg = document . createElement ( 'img' ) ;
32
+ newBackImg . classList . add ( "slide__backImg" ) ;
33
+ newBackImg . src = `${ backImgUrl } ` ;
34
+ backgroundSlide . appendChild ( newBackImg ) ;
31
35
// console.dir(newImg);
32
36
} ) ;
33
37
}
34
- const setSlides = ( data ) => {
38
+ const setSlides = ( ) => {
35
39
const slides = document . querySelectorAll ( ".frontImages__img" ) ;
40
+ const backImg = document . querySelectorAll ( ".slide__backImg" ) ;
36
41
const title = document . querySelector ( ".info__title" ) ;
37
42
const overview = document . querySelector ( ".info__overview" ) ;
38
43
39
44
slides [ activeImgNo ] . classList . add ( "active" ) ;
45
+ backImg [ activeImgNo ] . classList . add ( 'active' ) ;
40
46
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]})`;
47
47
title . innerHTML = slideMovieNames [ activeImgNo ] ;
48
48
overview . innerHTML = slideMovieOverview [ activeImgNo ] ;
49
49
// console.dir(slides);
@@ -54,7 +54,7 @@ const getSlideImages = async () => {
54
54
const res = await axios . get ( APIUrl ) ;
55
55
// console.log(res.data.results);
56
56
placeSlideImages ( res . data . results ) ;
57
- setSlides ( res . data . results ) ;
57
+ setSlides ( ) ;
58
58
}
59
59
catch ( err ) {
60
60
console . log ( err ) ;
@@ -64,7 +64,11 @@ getSlideImages();
64
64
65
65
const moveSlideToRight = ( ) => {
66
66
const slides = document . querySelectorAll ( ".frontImages__img" ) ;
67
+ const backImg = document . querySelectorAll ( ".slide__backImg" ) ;
68
+
67
69
slides [ activeImgNo ] . classList . remove ( "active" ) ;
70
+ backImg [ activeImgNo ] . classList . remove ( "active" ) ;
71
+
68
72
activeImgNo ++ ;
69
73
if ( activeImgNo > slides . length - 1 ) {
70
74
activeImgNo = 0 ;
@@ -73,7 +77,11 @@ const moveSlideToRight = () => {
73
77
}
74
78
const moveSlideToLeft = ( ) => {
75
79
const slides = document . querySelectorAll ( ".frontImages__img" ) ;
80
+ const backImg = document . querySelectorAll ( ".slide__backImg" ) ;
81
+
76
82
slides [ activeImgNo ] . classList . remove ( "active" ) ;
83
+ backImg [ activeImgNo ] . classList . remove ( "active" ) ;
84
+
77
85
activeImgNo -- ;
78
86
if ( activeImgNo < 0 ) {
79
87
activeImgNo = slides . length - 1 ;
0 commit comments