Jquery平滑滚动点击(两个方向,向下和向上)
jquery smooth scroll on click (both directions, down and up)
我有一个基本的脚本,可以在用户点击锚定链接时平滑地滚动到锚定链接。我的问题是,平滑的滚动似乎只工作一种方式,当我点击一个"到顶部"的链接,页面只是跳转…
$(function(){
// Smooth scrolling for anchored links
$('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
}, 2000);
return false;
}
}
});
// Scroll down automatically on page load
$('html, body').animate({
scrollTop: $('.destination').offset().top
}, 2000);
});
https://jsfiddle.net/p70d4doq/22/任何帮助将非常感激!
谢谢,安德烈亚斯
您忘记添加这一点了:
$('a[href="#"]').click(function () {
$('html, body').animate({
scrollTop: 0
}, 2000);
});
请不要给不工作的小提琴!发布链接前检查。
工作小提琴:https://jsfiddle.net/a5u0zzLr/
相关文章:
- JQuery合并了keyup和focusout两个函数
- 如何使用 node.js 比较两个 json 数组
- 为复选框javascript指定两个值
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 单击时切换两个图像
- 我可以'我似乎不知道如何修复javascript中的两个lint.有人能帮我理解吗
- 基于两个条件退出While循环
- 将页面分成两部分,并将两个部分滚动到相反的方向
- 我是否需要为手机的两个方向编写不同的代码集
- 如何在相反的方向上垂直移动两个列表
- 使滑动过渡在两个方向上都是无限的
- 如何在两个方向上旋转图像90
- 使用Three.js获取两个3d矢量之间的方向
- Jquery平滑滚动点击(两个方向,向下和向上)
- 在相反的方向上旋转两个图像
- 地图盒通过两个标记绘制方向
- 我如何旋转两个图像[在同一画布上]在相反的方向
- 赢得两个方向't在Google Maps API中加载
- 两个静态标记之间的Google Maps API v3 WEB JS方向
- Flexslider-如何使用单个方向Nav使两个滑块一起工作(图像和段落文本)