In first demo I'm using jquery 2.1.1
and getting offset top of a
tag 22
in chrome, and its remains same while scrolling,
but when I'm using jquery 3.1.1
offset changes while scrolling.
Demo 1 with jquery 2.1.1
console.log($('a').offset().top);
$(window).scroll(function() {
console.log($('a').offset().top);
})
body {
height: 1200px;
}
a {
font-size: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#">hidden anchor</a>
Demo 2 with jquery 3.1.1
console.log($('a').offset().top);
$(window).scroll(function() {
console.log($('a').offset().top);
})
body {
height: 1200px;
}
a {
font-size: 0;
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<a href="#">hidden anchor</a>
Why this is happening.