Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 滚动条和平滑滚动代码_Javascript_Jquery_Html_Css_Scroll - Fatal编程技术网

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;
  }
}
  });
});