Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

to scroll within a div

Status
Not open for further replies.

keak

Programmer
Sep 12, 2005
247
CA
Hi there,
I have a DIV that has a vertical scroll bar within an html page. (the main HTML page has its own scrollbar as well).

I was trying to make it so that when a user clicks within a div and then scrooll, it scrolls the content within the div, and not the main HTML scrollbar (and when the user clicks outside of it, it scrolls the main HTML).

Is there a way to do this in javascript?
 
I'm pretty sure there's an onscroll event. Perhaps it's IE only.

When you say "click and scroll"... do you mean like with a mouse that has a scroll wheel on top?

How are your DIVs behaving? What you want to do sounds like the behavior I have seen on every web page I've ever visited (that also have DIVs with scroll bars).

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Actually I have my scroll bar hidden, so yes I mean for the users to be able to scroll with their mouse (and not draggign the scrollbar).

if I hold down my mouse within the div and drag it down (highlighting the contents), the div scrolls ok. But I am trying to make this scrolling done wiht the mouse.

I will try looking into that onscroll event.
 
I think that if a mouse is equipped with a scroll wheel, then the behavior you are seeking is what will occur naturally, but if it isn't and for users without the scroll wheel, you are probably more interested in the onclick and onmousemove events. You might also change the style of the cursor to 'crosshair' to indicate that it is in scroll mode. 'just a thought.

Good luck!

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top