javascript - 使用 javascript 在 Chrome/Mac 上强制 "overscrolling"

标签 javascript jquery google-chrome

当您达到文档的极限时,您可以继续滚动,并且可以在文档弹回(过度滚动)之前看到文档后面的背景。

如何使用 javascript 强制窗口像这样过度滚动?

最佳答案

这不是最终的解决方案,因为我认为动画不完美而且它实际上只适用于桌面,但它至少可以让您入门。我所做的是增加滚动动画的主体高度。

 $(document).on('scroll mousewheel', function (e) {
    //Check for mousewheel scrolling down (or not used at all)
    if (!e.originalEvent || !e.originalEvent.wheelDeltaY
       || e.originalEvent.wheelDeltaY < 0) {
       if ($(window).height() + $(this).scrollTop() == $(this).height()) {
          //Prevent simultaneous triggering of the animation
          if (!$("body").data('bouncing')) {
             $("body").height(function (_, h) { return h + 15; })
                 .data('bouncing', true);
             $("body, html").animate({
                'scrollTop': '+=15'
             }, 125).animate({
                'scrollTop': '-=15'
             }, {duration: 125, complete: function () {
                $(this).height(function (_, h) { return h - 15; })
                    .data('bouncing', false);
             }});
          }
       }
    }
 }).on('keydown', function (e) {
    //The "down" arrow; still bounces when pressed at the bottom of the page
    if (e.which == '40') {
       $(this).trigger('scroll');
    }
 });

关于javascript - 使用 javascript 在 Chrome/Mac 上强制 "overscrolling",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15035828/

相关文章:

javascript - Chrome 不会在需要时重绘页面

javascript - 未捕获的语法错误 : Unexpected token ILLEGAL when putting html in var

javascript - 注册后重定向 [react, react-router, alt]

javascript - 根据下拉菜单填充输入表

javascript - 我如何在 jQuery 中获取 CSS 中无限动画的当前状态

CSS 未在 IE 中显示(任何版本)

javascript - Jquery Mobile 从 javascript 或 jquery 更改数据添加后退按钮 ="true"的文本?

javascript - 如何使用 phantomjs 下载包含所有相关内容的网页

javascript - 如何从 Javascript FileReader 获取文件名?

javascript - 如何为 Gmail 制作稳定的书签