jquery-smooth-scroll icon indicating copy to clipboard operation
jquery-smooth-scroll copied to clipboard

Strip smoothScroll from urlPath

Open schroef opened this issue 5 years ago • 0 comments

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 avatar Mar 03 '20 22:03 schroef