I want intercep an intersection when the target element is at 100px from the intersection root
for make it, i have setted rootMargin with '100px 0px 100px 0px'.
In this example the intersection become when the first pixel of target element (red box) enter into the intersetion root
i want the intersetion become when the target element is at 100px from the intersection root (grey area)
var io = new IntersectionObserver(function(entries){
document.getElementById('info').innerHTML = entries[0].isIntersecting ? 'isIntersecting = true' : 'isIntersecting = false';
}, {
rootMargin: '100px 0px 100px 0px'
});
io.observe(document.getElementById('target'));
* {
padding: 0;
margin: 0;
}
.pad {
height: 1000px;
}
#target {
background: rgb(237, 28, 36);
height: 100px;
outline: 100px solid rgba(0,0,0,0.2);
}
#info {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 2rem;
}
<div class="pad"></div>
<div id="target"></div>
<div class="pad"></div>
<span id="info">isIntersecting = true</span>