flesler / jquery.localScroll

Animated anchor navigation made easy with jQuery

Home Page:http://demos.flesler.com/jquery/localScroll/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Offset is not respected when linking to a hash from another page

jaydenseric opened this issue · comments

With localScroll version 1.3.5 and Chrome 37 the offset option is not respected when linking to a hash from another page.

It seems to work in Firefox 37 and Safari 6.1.2.

Seem like it could have to do with the change on e878682.

Could you try using this previous version of the file and see if it works as expected with that one?

I've been changing that section of the code back and forth :(

@jaydenseric If you mean clicking a link on pageA to pageB#someid, it never worked for me and i've been using jQuery scrollTo from years. I've solved the issue with this snippet:

        var localOffset;
	var hashOffset;
	var finalOffset;
	
	localOffset = jQuery('.site-header').outerHeight();

        function offsetAnchor() {
		if(location.hash.length !== 0) {
			hashOffset = jQuery(location.hash).offset().top;
			finalOffset = hashOffset - localOffset;
			window.scrollTo(window.scrollX, finalOffset);
		}
	}
	window.setTimeout(offsetAnchor, 250);

edit: just noticed the post is from 2014 💯