Add or reduce a value in .top when clicking the link for ID

0

I have a jQuery function that does a smooth scrolling on the page by clicking the ID link.

$(function() {
		$('a[href*="#"]:not([href="#"])').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = $(this.hash);
			target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
			if (target.length) {
				$('html, body').animate({
					scrollTop: target.offset().top
				}, 1000);
				return false;
			}
		}
		});
	});

It works perfectly. The problem is that I have a div with position fixed of height: 100px that gives an overlay in the first 100px of the div. I need to add these 100px at the time the Scroll happens, by clicking on the div. I have no idea how to do this.

    
asked by anonymous 19.01.2017 / 06:14

1 answer

1

var targetOffset = $ target.offset (). top-100;

Or take the height of the header element for the extra offset.

var targetOffset = $ target.offset (). top - $ ("element"). outerHeight (true);

    
10.02.2017 / 01:29