views:

165

answers:

1

I want to create my own implementation of a div with scroll, without using overflow: scroll;

But I can't seem to figure out how to get the content offset of a div, does anyone know?

+1  A: 

I'm not entirely sure I understand what you mean by "content offset", but one way to implement scrolling-like behavior would be this:

<div id="a">
    <div id="b">
        Lorem ipsum dolor pipsum.
    </div>
</div>

#a {
    position: relative;
    overflow: hidden;
    height: 100px;
}
#b {
    position: absolute;
    height: 200px;
}

Now you could scroll #b within #a by changing the #b's top property. Scrolling it to bottom would mean setting top to -100px, and 0 to reset.

Implementing an actual scroll-bar would be up to you, though. As well as things like mouse-wheel support.

Reinis I.
Thanks, that works :)And I didn't say I was going to implement a scrollbar ;)
MrThys