将scrollByX和scrollByY分配给jScrollPane中的jspDrag?

发布于 2024-10-13 09:55:45 字数 261 浏览 1 评论 0原文

我正在为一个涉及水平滚动的项目实现 jScrollPane。客户端希望水平滚动以增量方式进行,以便用户基本上可以从一张幻灯片跳到另一张幻灯片。

我可以使用 jScrollPane 的 API 和“scrollByX”在箭头上执行此操作。然而,问题在于用户可以单击滚动条并前后拖动并以这种方式滚动内容。

有没有办法将“scrollByX”(或“scrollByY”,就此而言)分配给jspDrag,以便当用户拖动滚动条时,滚动不是连续的,而是增量的?

提前致谢。

I am implementing jScrollPane for a project that involves horizontal scrolling. The client wants the horizontal scrolling to take place in increments, so that the user can basically jump from slide to slide.

I can do this on the arrows using jScrollPane's API and "scrollByX". However, the problem lies with the scrollbar that the user can click on and drag back and forth and scroll the content that way.

Is there any way to assign "scrollByX" (or "scrollByY", for that matter) to jspDrag so that when the user drags the scrollbar, the scrolling isn't continuous, but in increments as well?

Thanks in advance.

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

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

发布评论

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

评论(1

猫七 2024-10-20 09:55:45

您可以在任何 jsp-scroll-x 事件之后监听 mouseup 事件,这样您就可以找出最近的项目在哪里,并使用 jScrollPane API 滚动到该元素的位置。我已经更新了您找到的示例,以便它以这种方式工作(正如您注意到的那样,它以前只向前滚动):

http://www.jsfiddle.net/dzvSC/14/

(显然这段代码是垂直工作的,但你可以将 y 更改为 x 以及将顶部更改为左侧等)

var api = $('.scroll-pane').jScrollPane().bind(
    'jsp-scroll-y',
    function(event, scrollPositionY, isAtBottom, isAtTop)
    {
        $(document)
            .unbind('mouseup.jsp-demo')
            .bind(
                'mouseup.jsp-demo',
                function()
                {
                    $(document).unbind('mouseup.jsp-demo');
                    var currentY = api.getContentPositionY(),
                        lastY = 0;
                    api.getContentPane().find('>*').each(
                        function()
                        {
                            var thisY = $(this).position().top,
                                destY;
                            if (thisY > currentY) {
                                destY = currentY - lastY > thisY - currentY ? thisY : lastY;
                                api.scrollToY(destY, true);
                                return false;
                            }
                            lastY = thisY;
                        }
                    );
                }
            );
    }
).data('jsp');

原始答案:

可以做你想做的事,我在某处写了一个例子 您可以在 jScrollPane 邮件列表 上找到它 - 在示例中它是垂直滚动窗格,当您释放滚动条时,它会动画到最近的图像。实际示例位于 jsfiddle.net 上。

我现在很着急,找不到这个例子,但这可能对你有帮助。如果当我下次在电脑前时你还没有找到它,我会尝试找到它并更新这个答案......

You can listen to the mouseup event after any jsp-scroll-x event and in that you can figure out where the nearest item is and use the jScrollPane API to scroll to the position of that element. I've updated the example you found so that it works in this manner (as you noticed it previously only scrolled forwards):

http://www.jsfiddle.net/dzvSC/14/

(obviously this code is working vertically but you can change the y's to x's and the top's to left's etc)

var api = $('.scroll-pane').jScrollPane().bind(
    'jsp-scroll-y',
    function(event, scrollPositionY, isAtBottom, isAtTop)
    {
        $(document)
            .unbind('mouseup.jsp-demo')
            .bind(
                'mouseup.jsp-demo',
                function()
                {
                    $(document).unbind('mouseup.jsp-demo');
                    var currentY = api.getContentPositionY(),
                        lastY = 0;
                    api.getContentPane().find('>*').each(
                        function()
                        {
                            var thisY = $(this).position().top,
                                destY;
                            if (thisY > currentY) {
                                destY = currentY - lastY > thisY - currentY ? thisY : lastY;
                                api.scrollToY(destY, true);
                                return false;
                            }
                            lastY = thisY;
                        }
                    );
                }
            );
    }
).data('jsp');

Original answer:

It is possible to do what you want and I wrote an example somewhere. You may be able to track it down on the jScrollPane mailing list - in the example it was a vertical scrollpane and it animated to the nearest image when you released the scrollbar. The actual example was on jsfiddle.net.

I'm in a rush now and can't find the example but that may help you to. If you haven't found it when I'm next in front of the computer I'll try to track it down and update this answer...

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