Javascript 滚动条和平滑滚动代码
请检查此页(例如) 我想知道我怎么能有这个Javascript 滚动条和平滑滚动代码,javascript,jquery,html,css,scroll,Javascript,Jquery,Html,Css,Scroll,请检查此页(例如) 我想知道我怎么能有这个 我想在firefox和chrome中支持一些东西 您可以使用锚定标记进行平滑滚动。 下面是结果 $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.host
我想在firefox和chrome中支持一些东西 您可以使用锚定标记进行平滑滚动。 下面是结果
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
哇,真烦人。我不建议你这样做。我的Chrome似乎有一些问题(滚动条结巴)。@FritsvanCampen真的吗?:-?谢谢你的评论
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});