简体   繁体   English

在相对位置内获取滚动位置 <div> 容器

[英]Get Scroll Position inside Relative Positioned <div> Container

Is there any way to find out how much someone has scrolled when the content is in a container div with position:relative. 有什么方法可以确定当内容位于具有position:relative的容器div中时,有人滚动了多少。 I can only seem to get scroll position using JavaScript or JQuery when position is set to absolute, but this disrupts the site layout. 当位置设置为绝对值时,我似乎只能使用JavaScript或JQuery来获得滚动位置,但这会干扰网站布局。 Is there any solution to this? 有什么解决办法吗?

doesn't seem to have any problem in fiddle: http://jsfiddle.net/dQ69u/ 小提琴似乎没有任何问题: http : //jsfiddle.net/dQ69u/

#container{
    position:relative;
    overflow-y:scroll;
    width:400px;
    height:400px;
    background-color:#CCC;
}
#scrollable{
    position:relative;
    width:80%;
    margin-left:10%;
    height:1000px;
    background-color:#000;
}

or even in this one: http://jsfiddle.net/dQ69u/1/ 甚至在这其中: http : //jsfiddle.net/dQ69u/1/

#container{
    position:relative;
    overflow:hidden;
    width:400px;
    height:400px;
    background-color:#CCC;
}
#scrollable{
    position:relative;
    width:80%;
    margin-left:10%;
    height:1000px;
    background-color:#000;
}
#scrollBox{
    position:relative;
    overflow-y:scroll;
    width:80%;
    margin-left:10%;
    height:400px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM