Content offset in Javascript
I want to create my own implementation of a div with scroll, without using overflow: scroll;
But I can't seem to f开发者_开发技巧igure out how to get the content offset of a div, does anyone know?
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.
精彩评论