Im trying to link to a specific section of my home page while maintaining a scroll spy feature.
With this code:
<li><a href="#sec1">About</a></li>
the scrollspy is functioning but if I try to access it from a page other than my home page it just adds "#sec1"
to the current page's url, to no effect.
If I change it to:
<li><a href="/#sec1">About</a></li>
It takes me to the correct section on the home page, but the scrollspy function no longer works.
js code
$(function(){/* smooth scrolling for scroll to top */
/* highlight the top nav as scrolling occurs */
$('body').scrollspy({ target: '#navbar' })
});
Any ideas?
you can try
this code will split the url to get sec1 or sec2 .... and then scroll to the div with id="sec1"
I mean if you redirect another page to www.website.com/anything#sec1 it will scroll the page to the div with id="sec1"
take a look at this DEMO
you can see this Jsffidle