File tree Expand file tree Collapse file tree
prototype/background-slider Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7+ < title > background slider</ title >
8+ < link rel ="stylesheet " href ="style.css ">
9+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css ">
10+ </ head >
11+ < body >
12+ < div class ="slide-container ">
13+ < div class ="slide active " style ="background-image: url('https://images.unsplash.com/photo-1567941085898-d5bf3ff007ad?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80'); "> </ div >
14+ < div class ="slide " style ="background-image: url('https://images.unsplash.com/photo-1595875197145-a0d6828b58e3?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bmF0dXJ8ZW58MHx8MHx8&auto=format&fit=crop&w=600&q=60'); "> </ div >
15+ < div class ="slide " style ="background-image: url('https://images.unsplash.com/photo-1587677958307-16d24f9c6735?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8bmF0dXJ8ZW58MHx8MHx8&auto=format&fit=crop&w=600&q=60'); "> </ div >
16+ < div class ="slide " style ="background-image: url('https://images.unsplash.com/photo-1592905745083-428088fd05de?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8bmF0dXJ8ZW58MHx8MHx8&auto=format&fit=crop&w=600&q=60'); "> </ div >
17+ < div class ="slide " style ="background-image: url('https://images.unsplash.com/photo-1577736759954-ab244d98cba7?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTF8fG5hdHVyfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=600&q=60'); "> </ div >
118
19+ < button class ="arrow left-arrow " id ="left ">
20+ < i class ="fas fa-arrow-left "> </ i >
21+ </ button >
22+ < button class ="arrow right-arrow " id ="right ">
23+ < i class ="fas fa-arrow-right "> </ i >
24+ </ button >
25+ </ div >
26+ < script src ="scrypt.js "> </ script >
27+ </ body >
28+ </ html >
Original file line number Diff line number Diff line change 1+ const body = document . body
2+ const slides = document . querySelectorAll ( '.slide' )
3+ const leftBtn = document . getElementById ( 'left' )
4+ const rightBtn = document . getElementById ( 'right' )
5+
6+ let activeSlide = 0
7+ rightBtn . addEventListener ( 'click' , ( ) => {
8+ activeSlide ++
9+ if ( activeSlide > slides . length - 1 ) {
10+ activeSlide = 0
11+ }
12+ BGWork ( )
13+ activeBGSlide ( )
14+ } )
15+ leftBtn . addEventListener ( 'click' , ( ) => {
16+ activeSlide ++
17+ if ( activeSlide < slides . length - 1 ) {
18+ activeSlide = 0
19+ }
20+ BGWork ( )
21+ activeBGSlide ( )
22+ } )
23+ BGWork ( )
24+ function BGWork ( ) {
25+ body . style . backgroundImage = slides [ activeSlide ] . style . backgroundImage
26+
27+
28+ }
29+
30+ function activeBGSlide ( ) {
31+ slides . forEach (
32+ slide => {
33+ slide . classList . remove ( 'active' )
34+ slides [ activeSlide ] . classList . add ( 'active' )
35+ } )
36+ }
Original file line number Diff line number Diff line change 1+
2+ body {
3+ background-image : url ('https://images.unsplash.com/photo-1567941085898-d5bf3ff007ad?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80' );
4+ display : flex;
5+ flex-direction : column;
6+ justify-content : center;
7+ align-items : center;
8+ overflow : hidden;
9+ height : 100vh ;
10+ margin : 0 ;
11+ background-position : center center;
12+ background-size : cover;
13+ transition : 0.4s ease;
14+ }
15+
16+ body ::before {
17+ content : '' ;
18+ position : absolute;
19+ top : 0 ;
20+ left : 0 ;
21+ width : 100% ;
22+ height : 100vh ;
23+ background-color : rgba (0 , 0 , 0 , 0.7 );
24+ z-index : -1 ;
25+ }
26+
27+ .slide-container {
28+ border : 3px solid black;
29+ height : 70vh ;
30+ width : 70vw ;
31+ position : relative;
32+ overflow : hidden;
33+ }
34+
35+ .slide {
36+ opacity : 0 ;
37+ height : 100vh ;
38+ width : 100vw ;
39+ background-position : center center;
40+ background-size : cover;
41+ position : absolute;
42+ top : -15vh ;
43+ left : -15vw ;
44+ transition : 0.4s ease;
45+ z-index : 1 ;
46+ }
47+ .slide .active {
48+ opacity : 1 ;
49+ }
50+
51+
52+
53+
54+
55+
56+
57+ .arrow {
58+ position : fixed;
59+ padding : 20px ;
60+ background-color : transparent;
61+ z-index : 100 ;
62+ font-size : 28px ;
63+ border : none;
64+ top : 50% ;
65+ color : chartreuse;
66+ transform : rotateY (-50% );
67+ }
68+ .arrow : focus {
69+ outline : 0 ;
70+ }
71+
72+ .left-arrow {
73+ left : calc (15vw - 65px )
74+ }
75+
76+
77+ .right-arrow {
78+ right : calc (15vw - 65px )
79+ }
You can’t perform that action at this time.
0 commit comments