How can I check when an entire element is in view?
In the example below, if a box comes into view, I want to change the background color of the box to red. Also, the top box (which should already be fully displayed on your screen) should automatically be red (since it's already fully in the view).
How can I do this?
https://jsfiddle.net/7gr1qkeq/
HTML:
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
CSS:
body {
margin: 50px;
}
.container {
width: 300px;
background: lightgrey;
padding: 50px;
}
.box {
display: block;
width: 100%;
height: 300px;
background: grey;
}
.box:not(:last-of-type) {
margin-bottom: 50px;
}