I wrote a script that does not allow the floating button to go above the area where the script is used, while scrolling down, the button climbs to the very bottom of the site. How to make it stop at the end of the block where my script is used?
<script type="text/javascript"> $(function() { var offset = $(".spoiler-hd").offset(); var topPadding = 45; $(window).scroll(function() { if ($(window).scrollTop() > offset.top) { $(".spoiler-hd").stop().animate({marginTop: $(window).scrollTop() - offset.top + topPadding}); } else {$(".spoiler-hd").stop().animate({marginTop: 300});};}); }); </script>