forked from MakeSchool-18/front-end-web-Q1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscroll-thing.html
69 lines (51 loc) · 1.45 KB
/
scroll-thing.html
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
<style>
.container {
height: 400px;
width: 400px;
margin: auto;
border: 10px solid #000;
overflow: scroll;
}
.box {
height: 400px;
}
.display {
text-align: center;
}
.completed {
border-color: red;
}
</style>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="display"></div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
var boxHeight = 400;
var scrollDistance = 2000; // 400 * 6 - 400
$(".container").scroll(function(event){
$(".display").html("scroll height: "+this.scrollHeight+" scroll top: "+this.scrollTop);
if (this.scrollTop == this.scrollHeight - boxHeight) {
$(".container").addClass("completed");
} else {
$(".container").removeClass("completed");
}
var p = this.scrollTop / scrollDistance;
var hue = 360 * p;
console.log(hue);
$("body").css({"background-color":"hsl("+hue+", 100%, 50%)"});
});
$(".box").each(function (i, el) {
var hue = 360 / 6 * i;
console.log($(this));
$(this).css({
backgroundColor: "hsl(" + hue + ", 100%, 50%)"
});
});
</script>