I have a function that decrease the width of the slider-side-hr to 0 when scrolling from the top of the page to -600 of the scrolling div height (which means before reaching the bottom of the scrolling div).
The slider sides are both fixed, one to right and the other to the left.
<div class="tower" id="tower2">
<div class="scroll-slider-hr">
<div class="slider-side-hr slider-side1"></div>
<div class="slider-side-hr slider-side2"></div>
</div>
</div>
It works perfectly fine and the width of both slider-side-hr decreasing to 0 when scrolling, but I have a problem when the scrolling div is NOT on the top of the page.
I need a condition that executes the function ONLY when (scrolling div) reaches the bottom of the page + 100px, which means I can see the slider-side-hr full width first (with 100px of the scrolling div height) then it starts to decrease to 0 on scrolling, and it should decrease to 0 when reaching half of the scrolling div
var $scrollingDiv = $("#tower2");
$(window).scroll(function() {
var winScrollTop = ($(document).scrollTop() + 0);
var zeroSizeHeight = $scrollingDiv.height() - 600;
var newSize = 250 * (1 - (winScrollTop / zeroSizeHeight));
$('.slider-side-hr').css({
width: newSize,
}, 500, 'easeInOutSine');
});
.container-full {
width: 100%;
margin-right: auto;
margin-left: auto;
}
.tower {
position: relative;
}
#tower1 {
/*margin-bottom: 700px*/
}
#tower2 {
background-image: linear-gradient(rgba(0, 0, 0, 0.5),rgba(0, 0, 0, 0.5));
background-position: center;
background-size: cover;
background-repeat: no-repeat;
height: 140vh;
background-attachment: fixed;
position: relative;
overflow: hidden;
}
.slider-side-hr {
position: absolute;
top: 0;
bottom: 0;
width: 250px;
height: 100%;
background: #ddd;
}
.slider-side1 {
left: 0;
}
.slider-side2 {
right: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<dic class="container-full">
<div class="tower" id="tower1">
</div>
<div class="tower" id="tower2">
<div class="scroll-slider-hr">
<div class="slider-side-hr slider-side1"></div>
<div class="slider-side-hr slider-side2"></div>
</div>
</div>
</div>