Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip smoothScroll from urlPath #113

Open
schroef opened this issue Mar 3, 2020 · 0 comments
Open

Strip smoothScroll from urlPath #113

schroef opened this issue Mar 3, 2020 · 0 comments

Comments

@schroef
Copy link

schroef commented Mar 3, 2020

Hi there,
i was cleaning a site a bit up and noticed that when i use the links to references on other pages, smoothScroll is added in the url path. Did a simple fix for that.

How it was
Screen Shot 2020-03-03 at 18 54 49

After the fix
Screen Shot 2020-03-03 at 18 54 28

Adjusted code

$(document).ready(function () {
	// Call $.smoothScroll if location.hash starts with "#smoothScroll"
	//var reSmooth = /^#smoothScroll/;
	var reSmooth = /^#smoothScroll/;
	var tag = /^#/;
	var id;
	if (reSmooth.test(location.hash)){
		// ADD FOCUS FOR TAG
		id = '#' + location.hash.replace(reSmooth, '');
		$(id).css('border-bottom', '4px solid #00aeef');
		$(id).css('padding-bottom', '1px');

	}
	
	if (reSmooth.test(location.hash)) {
		// Strip the "#smoothScroll" part off (and put "#" back on the beginning)
		id = '#' + location.hash.replace(reSmooth, '');
		// Strip the "#smoothScroll" part off path 
		location.hash = location.hash.replace(reSmooth, '');
		$.smoothScroll({
			scrollTarget: id,
			offset: -100
		});
	}
	else if (tag.test(location.hash)) {
		// Strip the "#smoothScroll" part off (and put "#" back on the beginning)
		id = location.hash;
		// Strip the "#smoothScroll" part off path
		location.hash = location.hash.replace(reSmooth, '');
		$.smoothScroll({
			scrollTarget: id,
			offset: -100
		});
	}
});
@schroef schroef changed the title Strip SmoothScrool from urlPath Strip smoothScroll from urlPath Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant