简体   繁体   English

当溢出被“隐藏”时,停止Firefox重置水平滚动位置?

[英]Stop Firefox resetting horizontal scroll position when overflow is “hidden”?

I have a horizontally scrolling div with sections inside. 我有一个水平滚动div,里面有部分。 I'm using Ariel Flesler's scrollTo plugin to scroll from one section to another. 我正在使用Ariel Flesler的scrollTo插件从一个部分滚动到另一个部分。

Please see: http://jsfiddle.net/carienf/qZeEe/ 请参阅: http//jsfiddle.net/carienf/qZeEe/

The fiddle works perfectly in IE 9, Safari 5.1, Opera 11.5 and Chrome 14 (all the latest versions). 这款小提琴在IE 9,Safari 5.1,Opera 11.5和Chrome 14(所有最新版本)中运行良好。 I can click on a link to scroll to the corresponding section and scroll or mousewheel around in it. 我可以点击一个链接滚动到相应的部分,然后在其中滚动或鼠标滚动。

Problem: In Firefox 7 (and earlier), when I have scrolled to Section 2 or Section 3 and then scroll down using the scrollbar , my position is reset to the first section . 问题:在Firefox 7(及更早版本)中,当我滚动到第2部分或第3部分然后使用滚动条向下滚动时我的位置将重置为第一部分 This also happens when I resize the browser window. 当我调整浏览器窗口大小时也会发生这种情况。 If I scroll using the mousewheel, Firefox behaves (in other words, I stay in the current section). 如果我使用鼠标滚轮滚动,Firefox会表现出来(换句话说,我会留在当前部分)。

My question is pretty much an exact repeat of this question: Problem mixing overflow-x, FireFox, and Javascript 我的问题几乎是这个问题的完全重复: 混合overflow-x,FireFox和Javascript的问题

Only, the accepted answer (which is to allow the horizontal scrollbar to be visible) doesn't work for my specific case. 只有,接受的答案(允许水平滚动条可见)对我的具体情况不起作用。 Also, the guy who posted the question has removed his example. 此外,发布问题的人已经删除了他的例子。 I really need that scrollbar to stay hidden and I really don't like the idea of hiding it behind a div. 我真的需要滚动条保持隐藏,我真的不喜欢将它隐藏在div后面的想法。

Is there a way (other than setting overflow to "auto") to stop Firefox from resetting my scroll position? 有没有办法(除了设置溢出到“自动”)阻止Firefox重置我的滚动位置? Or some other way to hide the scrollbar? 或者其他一些隐藏滚动条的方法?

UPDATE : Updated Firefox to 8.0 (still a beta version) and then the behaviour is consistent with the other browsers. 更新 :将Firefox更新到8.0(仍然是测试版),然后行为与其他浏览器一致。

I just ran into the same exact issue. 我刚刚遇到了同样的问题。 When my "modal window" pops up, I set html.noscroll { overflow: hidden } , which unfortunately causes the window to scroll-to-top. 弹出我的“模态窗口”时,我设置了html.noscroll { overflow: hidden } ,不幸的是导致窗口滚动到顶部。

Here's the only solution I could make work: 这是我可以做的唯一解决方案:

function RemoveScrollbar(html) {
    var scrollTop = html.scrollTop;
    html.addClass('noscroll');
    html.scrollTop = scrollTop;
}

This is MooTools code, but super simple to convert to jQuery or other frameworks. 这是MooTools代码,但转换为jQuery或其他框架非常简单。

I can see a couple of options. 我可以看到几个选项。

  1. clip off the scroll bar. 剪掉滚动条。 Takes some measuring and you have to position absolutely. 进行一些测量,你必须绝对定位。
  2. Add a 2nd div outside that does the vertical scrolling. 在外面添加第二个div进行垂直滚动。 That breaks your code as it currently stands, but it does resolve the scrolling problem. 这会破坏您目前的代码,但它确实解决了滚动问题。 jsfiddle.net/s2YFM jsfiddle.net/s2YFM

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

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