【问题标题】:Get Scroll Position inside Relative Positioned <div> Container获取相对定位 <div> 容器内的滚动位置
【发布时间】:2014-06-25 12:08:40
【问题描述】:

当内容位于容器 div 中时,有什么方法可以找出某人滚动了多少位置:relative。当位置设置为绝对时,我似乎只能使用 JavaScript 或 JQuery 获得滚动位置,但这会破坏站点布局。有什么解决办法吗?

【问题讨论】:

  • 你能发布你的html和脚本吗

标签: javascript jquery web


【解决方案1】:

fiddle 似乎没有问题: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;
}

【讨论】:

  • 是的,我认为我的 CSS 中缺少一些导致问题的元素。看起来我需要为一个人定义一个高度。谢谢。
猜你喜欢
  • 1970-01-01
  • 2018-12-05
  • 2014-03-19
  • 2020-08-17
  • 1970-01-01
  • 2022-11-02
  • 2012-12-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多