File tree Expand file tree Collapse file tree 3 files changed +85
-0
lines changed
Expand file tree Collapse file tree 3 files changed +85
-0
lines changed 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 name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Document</ title >
7+ < link rel ="stylesheet " href ="style.css ">
8+ </ head >
9+ < body >
10+ < h1 class ="heading "> Scroll to see the Animation</ h1 >
11+
12+
13+ < div class ="content "> Content 1</ div >
14+ < div class ="content "> Content 2</ div >
15+ < div class ="content "> Content 3</ div >
16+ < div class ="content "> Content 4</ div >
17+ < div class ="content "> Content 5</ div >
18+ < div class ="content "> Content 6</ div >
19+ < div class ="content "> Content 7</ div >
20+ < div class ="content "> Content 8</ div >
21+
22+
23+ < script src ="script.js "> </ script >
24+ </ body >
25+ </ html >
Original file line number Diff line number Diff line change 1+ const contents = document . querySelectorAll ( '.content' ) ;
2+
3+ const checkBoxes = ( ) => {
4+ const triggerBottom = ( window . innerHeight / 5 ) * 4 ;
5+ contents . forEach ( ( content ) => {
6+ const boxTop = content . getBoundingClientRect ( ) . top ;
7+ if ( boxTop < triggerBottom ) {
8+ content . classList . add ( 'show' ) ;
9+ } else {
10+ content . classList . remove ( 'show' ) ;
11+ }
12+ } ) ;
13+ } ;
14+
15+ window . addEventListener ( 'scroll' , checkBoxes ) ;
16+ checkBoxes ( ) ;
Original file line number Diff line number Diff line change 1+ * {
2+ box-sizing : border-box;
3+ }
4+
5+ body {
6+ font-family : Georgia, 'Times New Roman' , Times, serif;
7+ margin : 0 ;
8+ padding : 20px ;
9+ background-color : # fffafa ;
10+ display : flex;
11+ flex-direction : column;
12+ align-items : center;
13+ overflow-x : hidden;
14+ }
15+
16+ .heading {
17+ display : flex;
18+ justify-content : center;
19+ }
20+
21+ .content {
22+ display : flex;
23+ flex-direction : column;
24+ align-items : center;
25+ width : 400px ;
26+ height : 200px ;
27+ border-radius : 10px ;
28+ background : rgb (84 , 84 , 248 );
29+ color : # fffafa ;
30+ font-size : 32px ;
31+ justify-content : center;
32+ margin : 20px ;
33+ box-shadow : 2px 4px 5px rgba (0 , 0 , 0 , 0.3 );
34+ transform : translateX (400% );
35+ transition : transform 0.5s ease;
36+ }
37+
38+ .content : nth-of-type (even ) {
39+ transform : translateX (-400% );
40+ }
41+
42+ .content .show {
43+ transform : translateX (0 );
44+ }
You can’t perform that action at this time.
0 commit comments