如何在窗口滚动移动功能中实现 JQuery 缓动?

发布于 2024-09-03 07:48:36 字数 621 浏览 2 评论 0原文

通过这段代码,我已经能够捕获鼠标滚轮的移动并将其应用于水平滚动条而不是垂直默认滚动条。

$('html').bind('mousewheel', function(event, delta) {
   window.parent.scrollBy(-120 * delta, 0);
   return false;
});

有什么方法可以将这个 jQuery 缓动动画添加到滚动运动中吗?

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.extend( jQuery.easing, {
   easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158; 
        if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
        return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
   }
});

提前非常感谢!

With this code I've been able to capture the mousewheel movement and apply it to the horizontal scroll bars instead of the vertical default.

$('html').bind('mousewheel', function(event, delta) {
   window.parent.scrollBy(-120 * delta, 0);
   return false;
});

Is there any way that I could add this jQuery easing animation to the scroll movement?

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.extend( jQuery.easing, {
   easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158; 
        if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
        return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
   }
});

Thank you so much in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木緿 2024-09-10 07:48:36

我认为你需要的是scrollTo插件。似乎符合要求,虽然我个人没有使用过。基本上应该能够像这样调用它,

$.scrollTo( -120*delta, {duration:1000,easing:'easeInOutBack',axis:'x'} )

这里找到插件演示。 jquery 插件站点目前似乎处于离线状态,但是当其备份时,可以在 此处

i think what you need is the scrollTo plugin. seems to fit the bill, though i haven't used it personally. basically should be able to call it like this

$.scrollTo( -120*delta, {duration:1000,easing:'easeInOutBack',axis:'x'} )

find the plugin demo here. the jquery plugin site appears to be offline currently, but when its back up, the plugin can be found here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文