File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 4
4
< meta charset ="UTF-8 ">
5
5
< title > Scroll Top</ title >
6
6
< style >
7
- .container { margin : 0 auto; width : 980px ; height : 1000px ; background-color : # f9f9f9 ; }
8
- .scrolltop { position : fixed; bottom : 10px ; left : 50% ; margin-left : 500px ; width : 30px ; height : 30px ; background-color : # fae321 ; }
7
+ .container { margin : 0 auto; width : 980px ; height : 1000px ; }
8
+ .scrolltop { position : fixed; bottom : 10px ; left : 50% ; margin-left : 500px ; width : 30px ; height : 30px ; background-color : # 3d9970 ; cursor : pointer ; }
9
9
</ style >
10
10
</ head >
11
11
< body >
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
+ < title > Sticky</ title >
6
+ < style >
7
+ body { margin : 0 ; }
8
+ .container-fluid { height : 150px ; background-color : # 39cccc ; }
9
+ .container { margin : 0 auto; width : 980px ; display : flex; }
10
+ .container .main { width : 800px ; flex : 1 ; }
11
+ .container .main .section { height : 400px ; }
12
+ .container .sidebar { padding : 20px ; flex : 0 0 180px ; }
13
+ .container .sidebar .elevator { height : 300px ; border : 1px soild # aaaaaa ; border-radius : 3px ; }
14
+ .sticky { position : fixed; top : 0 ; }
15
+ </ style >
16
+ </ head >
17
+ < body >
18
+ < div class ="container-fluid " id ="heading "> </ div >
19
+ < div class ="container ">
20
+ < div class ="main ">
21
+ < div class ="section " style ="background-color: #0074d9 "> </ div >
22
+ < div class ="section " style ="background-color: #ff4136 "> </ div >
23
+ < div class ="section " style ="background-color: #01ff70 "> </ div >
24
+ < div class ="section " style ="background-color: #001f3f "> </ div >
25
+ < div class ="section " style ="background-color: #f012be "> </ div >
26
+ </ div >
27
+ < div class ="sidebar "> </ div >
28
+ </ div >
29
+ < script src ="http://code.jquery.com/jquery-2.1.1.min.js "> </ script >
30
+ < script type ="text/javascript ">
31
+ $ ( function ( ) {
32
+
33
+ $ ( window ) . on ( 'scroll' , function ( ) {
34
+ if ( $ ( this ) . scrollTop ( ) > $ ( '#heading' ) . offset ( ) . top ) {
35
+ $ ( '.sidebar' ) . addClass ( 'sticky' ) ;
36
+ } else {
37
+ $ ( '.sidebar' ) . removeClass ( 'sticky' ) ;
38
+ }
39
+ } ) ;
40
+ } )
41
+ </ script >
42
+ </ body >
43
+ </ html >
You can’t perform that action at this time.
0 commit comments