I am trying to track the scroll event produced by the automatic scrolling occurred due to going to anchor hash in the URL. For example http://example.com/page.html#theID
it should scroll to the DOM element of id
equals to theID
.
I need to track this event to overcome Bootstrap navbar from covering that element by increasing its padding or scrolling to point more near than it from the top to make sure it will not be covered. I have tried the following code:
...
<script>
$(document).ready(function(){
$(this).on("scroll",function(){
alert('Scroll Event...');
})
})
<script>
</body>
</html>
When loading the page with the anchor in the URL as described above, the above code does not work. However, it works only when I, manually, scroll the page.
Hence, Is there any way to track the automatic scroll of going to an anchor?