当我单击导航按钮时,我使用 jQuery 更改 URL 哈希。但是当我使用鼠标滚轮滚动时,URL 不会改变。我怎样才能做到这一点?
如何使用它来完成
window.history.pushState(“object or string”, “Title”, “/new-url”);
我无法理解它。请帮忙
我的 JavaScript 代码
$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;
});
});
});
html代码是
<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>