I have a parent div with a list of div's.
In parrent div I also added fixed positioned div on the top of parent div.
Based on some action I call:
$('#parent').animate({
scrollTop: $("#" + itemId).offset().top - $('#parent').offset().top + $('#parent').scrollTop()
}, 500);
This successfully scroll to a div and put it on the top.
The issue is that when searched div is on the top I can't see it because it is bellow fixed div.
<div id="parent">
<div id="fixedDiv" style="position: fixed;
z-index: 999;
background: #000;
width: 300px;">
... some elements ...
</div>
<ul>
... list of divs...
</div>
Is there some solution to scroll to div padded from the top of parent?
This is what I use, for a smooth scroll with 10px of upper padding:
$('body').animate({scrollTop: $('#div').offset().top-10},1000);
- $('#fixedDiv').height()
at end of scrollTop line will do :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With