33window . onload = function ( )
44{
55 var imageSource = [
6- "https://images.unsplash.com/photo-1595589981991-7f37459639c5 ?ixlib=rb-1.2.1&auto=format&fit=crop&w=500 &q=60 " ,
7- "https://images.unsplash.com/photo-1595100930017-8d4112e87959 ?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9& auto=format&fit=crop&w=500 &q=60 " ,
8- "https://images.unsplash.com/photo-1595024600400-2a49b9fce270 ?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9& auto=format&fit=crop&w=500 &q=60 " ,
6+ " https://images.unsplash.com/photo-1595882625224-eeaced8da8fb ?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9& auto=format&fit=crop&w=750 &q=80 " ,
7+ " https://images.unsplash.com/photo-1569531964322-7bced896a6a8 ?ixlib=rb-1.2.1&auto=format&fit=crop&w=667 &q=80 " ,
8+ " https://images.unsplash.com/photo-1569165962688-d5ae57b32dc0 ?ixlib=rb-1.2.1&auto=format&fit=crop&w=750 &q=80 " ,
99 "https://images.unsplash.com/photo-1508269757141-a5eaf8a31ef4?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" ,
1010 "https://images.unsplash.com/photo-1432889490240-84df33d47091?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" ,
1111 "https://images.unsplash.com/photo-1484896104369-90eb48a7596b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60"
@@ -14,11 +14,52 @@ window.onload=function()
1414
1515 let backButton = document . querySelector ( ".back" ) ;
1616 let forwardButton = document . querySelector ( ".forward" ) ;
17+ let autoBack = document . querySelector ( ".auto-back" ) ;
18+ let autoForward = document . querySelector ( ".auto-forward" ) ;
19+ let stop = document . querySelector ( ".stop" ) ;
1720
1821 var imageEl = document . querySelector ( ".image" ) ;
1922 var currentIndex = 0 ;
23+ var slideshow1 ;
24+ var slideshow2 ;
25+
26+
27+ autoForward . addEventListener ( "click" , function ( ) {
28+ clearInterval ( slideshow2 ) ;
29+
30+ slideshow1 = setInterval ( function ( ) {
31+ if ( currentIndex < 0 || currentIndex >= imageSource . length )
32+ {
33+
34+ currentIndex = 0 ;
35+ return ;
36+ }
37+ console . log ( currentIndex ) ;
38+ imageEl . src = imageSource [ currentIndex ] ;
39+ currentIndex = currentIndex + 1 ;
40+
41+ } , 1000 ) ;
42+ } ) ;
43+
44+ autoBack . addEventListener ( "click" , function ( ) {
45+ clearInterval ( slideshow1 ) ;
46+
47+ console . log ( "autoback index" + currentIndex ) ;
48+
49+ slideshow2 = setInterval ( function ( ) {
50+ if ( currentIndex < 0 || currentIndex >= imageSource . length )
51+ {
52+ currentIndex = imageSource . length - 1 ;
53+ }
54+ console . log ( currentIndex ) ;
55+ imageEl . src = imageSource [ currentIndex ] ;
56+ currentIndex = currentIndex - 1 ;
57+ } , 1000 ) ;
58+ } ) ;
2059
2160 backButton . addEventListener ( "click" , function ( ) {
61+ clearInterval ( slideshow1 ) ;
62+ clearInterval ( slideshow2 ) ;
2263 if ( currentIndex <= 0 )
2364 return ;
2465 else
@@ -27,9 +68,10 @@ window.onload=function()
2768 imageEl . src = imageSource [ currentIndex ] ;
2869 }
2970
30-
3171 } ) ;
3272 forwardButton . addEventListener ( "click" , function ( ) {
73+ clearInterval ( slideshow1 ) ;
74+ clearInterval ( slideshow2 ) ;
3375 if ( currentIndex >= imageSource . length - 1 )
3476 return
3577 else {
@@ -38,4 +80,9 @@ window.onload=function()
3880 }
3981
4082 } ) ;
83+
84+ stop . addEventListener ( "click" , function ( ) {
85+ clearInterval ( slideshow1 ) ;
86+ clearInterval ( slideshow2 ) ;
87+ } )
4188}
0 commit comments