在相对位置中获取滚动条位置

Get Scroll Position inside Relative Positioned <div> Container

本文关键字:位置 滚动条 获取 相对      更新时间:2023-09-26
容器。

是否有办法找出有多少人滚动时,内容是在一个容器div与位置:相对。当位置设置为绝对时,我似乎只能使用JavaScript或JQuery获得滚动位置,但这会破坏站点布局。有什么解决办法吗?

在小提琴中似乎没有任何问题: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;
}

甚至在这个: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;
}