我使用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>
你的导航按钮是怎么样的? –
我编辑的问题请参阅 –
你说你想在用户滚动页面时做些什么,但是你的代码负责处理[onscroll事件](http://www.w3schools.com/jsref/event_onscroll.asp) ? – Sergey