How to drag and scroll in a div with jQuery

2019-01-22 04:11发布

问题:

I've been looking around for some time now, but I can't find a way to combine these elements:

I want a 100% width div, with 1 row of elements. I need to scroll through this div, just like: http://jqueryfordesigners.com/demo/scrollable-timelines.html

So with a hidden overflow and such.

But now I want some sort of smooth ease when I let go of the mouseclick, so it'll be like a sort sweep. So when I drag the screen from left to right, and let go of the mouse, it'll move on for 1 sec and linearly slowing down. Hm, am I making sense?

Does anyone know of any scripts or some tips to put me back on track?

Don

回答1:

Utterscroll is a drag and scroll library I've written:

GitHub: https://github.com/debiki/utterscroll
GitHub hosted demo: http://rawgit.com/debiki/utterscroll/master/utterscroll-example.html
Demo and blog post: http://www.debiki.com/dev/utterscroll

It differs from other libraries in that it 1) understands if you intend to select text, rather than scrolling (note that in the example linked to by the question, it's not possible to select text), and 2) it needs no, or almost no, configuration.

Utterscroll stops when you release the mouse though (just like Dragscrollable, in the answer above, does.)