开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜