【发布时间】:2012-11-26 10:08:47
【问题描述】:
我有以下带有 CSS .container { overflow: scroll; } 等的 HTML。
<body>
<div class="container">
<div id="markers"></div>
<img id="map" src="/img/map.jpg"/>
</div>
</body>
map.jpg 很大,我想滚动到这样的固定位置:
$(function(){
console.log($('.container').scrollTop());
$('.container').scrollTop(1000);
console.log($('.container').scrollTop());
console.log($('.container').scrollLeft());
$('.container').scrollLeft(1750);
console.log($('.container').scrollLeft());
});
scrollLeft 工作正常,但 scrollTop 不行。下面是控制台输出。
0
0
0
1750
找了半个小时还是不知道怎么解决……
更新: CSS 关于 .container #markers 和 #map
.container { overflow: scroll; width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; padding: 0; }
#map { width: 5000px; max-width: 5000px; height: 2907px; max-height: 2907px; cursor: crosshair; }
#markers { position: relative; top: 0; left: 0; width: 0; height: 0; margin: 0; padding: 0; }
【问题讨论】:
-
你能给我们展示更多关于 .container、#markers 和 #map 的 CSS 代码吗?
-
@Sybio 我已经更新了问题。
-
这很奇怪,也许可以尝试溢出:auto on .container 而不是滚动。
-
@Sybio 我设法通过添加 position: absolute; 来修复它到.container
-
我在下面的小提琴链接上做了一个例子,你可以看到他们想要什么