I've got a floating navigation bar at the top of my website and I'm using the following code to scroll to various div
anchor points.
<script type="text/javascript">
$(document).ready(function () {
$('a[href^="#"]').on('click', function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top - 100 // floatnav height
}, 900, 'swing', function () {
window.location.hash = '1' + target;
});
});
});
</script>
I'd like to be able to make the offset different depending on the anchor. Some of them are full page images that don't need an offset as nothing is really lost behind the navigation bar, whereas some start with text so the navigation bar needs to sit above them so that it does not hide content.