May 21, 2010

Is there an easy way to do click-and-drag scrolling in text frames?

Question by Skilldrick

I have a div with overflow:auto and a scroll bar, and I’d like to be able to drag the contents to scroll. I don’t need to be able to select text. Is there an easy way to do this? A jQuery plugin would be good, otherwise plain old JavaScript would be fine.

It seems I haven’t made myself clear enough. There’s a div with a fixed height that I want to scroll. Instead of picking up the scroll bar, I want to click and drag inside the text in the opposite direction. Like on an iPhone. Like in Photoshop when you hold down space and drag.

-------------------
|               | |
|               | |
|               |||
|               | |
|         <----------- click here and drag to scroll.
|               | |
|               | |
-------------------

Answer by John Hartsock

Here is a nice implemenation of drag and scroll divs

http://plugins.jquery.com/project/Dragscrollable

Answer by Starx

There is plugin in Jquery UI called draggable
through this you can change any element into draggable object

Here is the link for the demo
http://jqueryui.com/demos/draggable/

It is as simple as this

<script type="text/javascript">
$(function() {
    $("#draggable").draggable();
});
</script>

It is also possible to make it scrollable inside a div. Check the demo page

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!