views:

206

answers:

3

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.
|               | |
|               | |
-------------------
A: 

hey,

Do you mean that content should be scrolling when you move the scrollbar?

Make new div for the content you want to be dragable, and put it on the div you are scrolling. check the code given.

<div style="position:relative; overflow:hidden;">
    <div id="dragableContent"
    style="float: left;display: none;background:none repeat scroll 0 0 white; border:1px solid #323C45; border-width:0px 1px 0px 1px;"></div>
    <div> This is you content div...</div>
</div>

then on page load, you can make the div visible after setting its content HTML.

$(document).ready(function() {
    stripColumnFromDiv('Your content Div ID');
    var scrollingDiv = $("#dragableContent");
    scrollingDiv.css({'position':'absolute','display':'block'});
});

where stripColumnFromDiv function is setting the data from your element to new empty dragableContent.

I hope this is what you want,and helps you.

thanks.

Paarth
A: 

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

Starx
Thanks for this. I don't see how to get the functionality I want - that is, dragging a scrollable div and scrolling within that div. (Like holding space in Photoshop).
Skilldrick
Something like this? http://jsfiddle.net/6SnpF/The scroll moves weirdly, but it could be fixed.
Adirael
@Adirael Close but no banana. I feel like any approach based on this would be hack upon hack upon hack. Thanks though.
Skilldrick
+3  A: 

Here is a nice implemenation of drag and scroll divs

http://hitconsultants.com/dragscroll_scrollsync/scrollpane.html

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

John Hartsock
Thank you - this is EXACTLY what I was after! I'm going to leave the bounty open for a few more days, but this is definitely the idea. I've edited your answer to add the jQuery plugin pages for the dragscrollable plugin used... hope you don't mind!
Skilldrick