/    Sign up×
Community /Pin to ProfileBookmark

How do i bring scrolling focus to a scrolling DIV?

My question concerns an absolutely positioned, scrolling DIV area on a page, such as the following:

<div style=”height:5em; width:5em; position:absolute; top:50%; left:50%; overflow:scroll”>
blah blah blah blah blablablablablablablah blah blah blah blah blablablablablablablah blah blah blah blah blablablablablablablah blah blah blah blah blablablablablablablah
</div>

When I position the mouse over this DIV, I want the content within it (not the whole page) to scroll when I use the mouse wheel. (This effect happens by default in Internet Explorer, but in other browsers I have to move the DIV’s scrollbar to make the content scroll; the mouse wheel always scrolls the whole page even if I click inside the DIV. I don’t want that.)

I tried

<div onmouseover=”this.focus()”>

but that did not work.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JonaSep 10.2004 — [font=trebuchet ms]Try taking absolute positioning off. Scrolling has never faired well with absolute positioning.[/font]
Copy linkTweet thisAlerts:
@oswaldauthorSep 10.2004 — Thanks Jona... but the problem is the same even without the absolute positioning.

On the other hand, I find that if I put a link inside the DIV, like so:

<div style="height:5em; width:5em; position:absolute; top:50%; left:50%; overflow:scroll">

<a href="." onmouseover="this.focus()">link</a>

blah blah blah blah blablablablablablablah blah blah blah blah blablablablablablablah blah blah blah blah blablablablablablablah blah blah blah blah blablablablablablablah

</div>

then placing the mouse pointer over the link will activate mouse-wheel scrolling inside the DIV. But I want the scrolling to work without doing that.
Copy linkTweet thisAlerts:
@JonaSep 10.2004 — [font=trebuchet ms]Hmm, sorry I don't know of any way to set focus to a DIV element. You could try the [/font][font=courier new]focus()[/font][font=trebuchet ms] method, but if that doesn't work it's all the browsers' faults. ? [/font]
×

Success!

Help @oswald spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...