javascript - 滚动条和平滑滚动代码

标签 javascript jquery html css scroll

请检查此页面(例如)

http://www.christinamichael.in/create-a-powerful-human-disintegration-effect-in-photoshop

我想知道我怎么会有这样的东西?

我希望 firefox 和 chrome 支持一些东西。

最佳答案

您可以使用 ANCHOR 标签进行平滑滚动。 以下结果。

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

关于javascript - 滚动条和平滑滚动代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21430684/

相关文章:

javascript - 如何通过 var 选择 JavaScript "Id"?

javascript - 如何使带有不可点击类的 <a> 标签?

javascript - Canvas 等距游戏引擎——移动 map

javascript - 在移动设备上跳过加载 div 内容

html - 创建三列提要布局

javascript - Jquery 滚动到基于数据属性的部分

javascript - 使用索引拆分来解析文本流日志

javascript - 使用 jQuery 复制(例如通过加载或查找)包含内联脚本的 HTML 标记 - 如何实现?

javascript - 在 AngularJS 中创建新服务有什么优势?

javascript - 使用正则表达式的 jQuery 验证插件自定义方法