I am using jQuery to change the URL hash when I click on the navigation button. But when I scroll using the mouse wheel the URL won't change. How can I do that? How can it be done using
window.history.pushState(“object or string”, “Title”, “/new-url”);
I am not able to understand it. Please help my javascript code
$j(document).ready(function () {
$j("#start1").click(function (e) {
e.preventDefault();
var section = this.href,
sectionClean = section.substring(section.indexOf("#"));
$j("html, body").animate({
scrollTop: $j(sectionClean).offset().top
}, 1000, function () {
window.location.hash = sectionClean;
});
});
});
$j(document).ready(function () {
$j("#start2").click(function (e) {
e.preventDefault();
var section = this.href,
sectionClean = section.substring(section.indexOf("#"));
$j("html, body").animate({
scrollTop: $j(sectionClean).offset().top
}, 1000, function () {
window.location.hash = sectionClean;
});
});
});
and html code is
<a href="#home" id="start1"style="text-decoration:none;position:absolute;right:450px;top:37px;font-weight:bold;color:white;font-size:15px;z-index:200;transition:0.5s" onmouseover="big(this)" onmouseout="small(this)"><span >HOME</span></a>
<span><a href="#products" id="start2" style="text-decoration:none;position:absolute;right:250px;top:37px;font-weight:bold;color:white;font-size:15px;transition:0.5s" onmouseover="big(this)" onmouseout="small(this)">PRODUCTS & SERVICES</a></span>