-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path5_2(practice)_move_multiple_objs.html
More file actions
235 lines (193 loc) · 7.71 KB
/
5_2(practice)_move_multiple_objs.html
File metadata and controls
235 lines (193 loc) · 7.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Rancho|Archivo-Black|Passero+One&effect=emboss">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
.jumbotron {
margin-bottom: 0px;
}
#tofix1.fixed {
position: fixed;
z-index: 99;
top: 0;
}
#tofix2.fixed {
position: fixed;
z-index: 99;
top: 50px;
}
#tofix3.fixed {
position: fixed;
z-index: 99;
top: 100px;
}
#tofix4.fixed {
position: fixed;
z-index: 99;
top: 150px;
}
#tofix5.fixed {
position: fixed;
z-index: 99;
top: 200px;
}
#tofix6.fixed {
position: fixed;
z-index: 99;
top: 250px;
}
.movingblock {
position: absolute;
height: 50px;
width: 50px;
background-color: black;
}
#moved11,
#moved21,
#moved31,
#moved41,
#moved51,
#moved61 {
left: 0px;
}
#moved12,
#moved22,
#moved32,
#moved42,
#moved52,
#moved62 {
right: 0px;
}
</style>
</head>
<body>
<div class="jumbotron text-center">
<h1 class="font-effect-emboss">6_1 practice: moving block horizontally</h1>
</div>
<div id="tofix1" class="container-fluid text-center" style="background-color:#CCC;width:100%;min-height:50px;">
<div id="moved11" class="movingblock"></div>
<div id="moved12" class="movingblock"></div>
</div>
<div class="container-fluid" style="min-height:1000px;"></div>
<div id="tofix2" class="container-fluid" style="background-color:#AAA;width:100%;min-height:50px;">
<div id="moved21" class="movingblock"></div>
<div id="moved22" class="movingblock"></div>
</div>
<div class="container-fluid" style="min-height:1000px;"></div>
<div id="tofix3" class="container-fluid" style="background-color:#888;width:100%;min-height:50px;">
<div id="moved31" class="movingblock"></div>
<div id="moved32" class="movingblock"></div>
</div>
<div class="container-fluid" style="min-height:1000px;"></div>
<div id="tofix4" class="container-fluid" style="background-color:#666;width:100%;min-height:50px;">
<div id="moved41" class="movingblock"></div>
<div id="moved42" class="movingblock"></div>
</div>
<div class="container-fluid" style="min-height:1000px;"></div>
<div id="tofix5" class="container-fluid" style="background-color:#444;width:100%;min-height:50px;">
<div id="moved51" class="movingblock"></div>
<div id="moved52" class="movingblock"></div>
</div>
<div class="container-fluid" style="min-height:1000px;"></div>
<div id="tofix6" class="container-fluid" style="background-color:#333;width:100%;min-height:50px;">
<div id="moved61" class="movingblock"></div>
<div id="moved62" class="movingblock"></div>
</div>
<div class="container-fluid" style="min-height:1000px;"></div>
<!--FOOTER section-->
<script>
$(function() {
$(document).ready(function() {
var tofix1_height = $('#tofix1').position().top; //Reserve the original height
var tofix2_height = $('#tofix2').position().top; //Reserve the original height
var tofix3_height = $('#tofix3').position().top; //Reserve the original height
var tofix4_height = $('#tofix4').position().top; //Reserve the original height
var tofix5_height = $('#tofix5').position().top; //Reserve the original height
var tofix6_height = $('#tofix6').position().top; //Reserve the original height
$(window).scroll(function() {
var document_height = $(document).height() - $(window).height();
var window_width = ($(window).width() - $('#moved11').width()) / 2;
var scroll_position = $(window).scrollTop(); //current position
console.log(scroll_position);
if (scroll_position >= tofix1_height) {
$('#tofix1').addClass('fixed');
} else {
$('#tofix1').removeClass('fixed');
}
if (scroll_position >= tofix2_height - 100) {
$('#tofix2').addClass('fixed');
} else {
$('#tofix2').removeClass('fixed');
}
if (scroll_position >= tofix3_height - 200) {
$('#tofix3').addClass('fixed');
} else {
$('#tofix3').removeClass('fixed');
}
if (scroll_position >= tofix4_height - 300) {
$('#tofix4').addClass('fixed');
} else {
$('#tofix4').removeClass('fixed');
}
if (scroll_position >= tofix5_height - 400) {
$('#tofix5').addClass('fixed');
} else {
$('#tofix5').removeClass('fixed');
}
if (scroll_position >= tofix6_height - 500) {
$('#tofix6').addClass('fixed');
} else {
$('#tofix6').removeClass('fixed');
}
var target_position = scroll_position / document_height * window_width;
$('#moved11').css({
'left': target_position
});
$('#moved12').css({
'right': target_position
});
$('#moved21').css({
'left': target_position - 50
});
$('#moved22').css({
'right': target_position - 50
});
$('#moved31').css({
'left': target_position - 100
});
$('#moved32').css({
'right': target_position - 100
});
$('#moved41').css({
'left': target_position - 150
});
$('#moved42').css({
'right': target_position - 150
});
$('#moved51').css({
'left': target_position - 200
});
$('#moved52').css({
'right': target_position - 200
});
$('#moved61').css({
'left': target_position - 250
});
$('#moved62').css({
'right': target_position - 250
});
});
});
});
</script>
</body>
</html>