简体   繁体   English

如何隐藏滚动(溢出:隐藏)?

[英]how to hide scroll (overflow:hidden)?

I have scrollable page with link which opens thickbox.我有带有打开厚框链接的可滚动页面。

(see example landme.ru/scroll-bug/ ) (参见示例landme.ru/scroll-bug/

I want to hide vertical scroll when thickbox is opened and stay on the bottom of the page.我想在打开厚框时隐藏垂直滚动并停留在页面底部。 Applying 'overflow:hidden' property to 'body' tag does not work in ie7.将 'overflow:hidden' 属性应用于 'body' 标签在 ie7 中不起作用。 If I use this property for 'html' tag, the page content is scrolled up before scroll will be hidden如果我将此属性用于“html”标签,则页面内容会在滚动隐藏之前向上滚动

sorry for my english对不起我的英语不好

UPD: Meanwhile I use such code: UPD:同时我使用这样的代码:

css: css:
.noscroll{overflow:hidden;}

js: js:

if ( ($.browser.msie) && ($.browser.version == '7.0')) {  
   $('html').addClass('noscroll');  
} else {  
   $('body').addClass('noscroll');  
}  

It works, but I still want to know, if there are any other methods它有效,但我仍然想知道,如果有任何其他方法

ok so the problem is with the height.好的,所以问题出在高度上。 You can't just specify overflow hidden on the wrap because it has no idea where to stop.您不能只指定在包装上隐藏的溢出,因为它不知道在哪里停止。 Wrap the "wrap" in a div with the style attributes of position:relative;用 position:relative 的样式属性将“wrap”包裹在一个 div 中; height:100%;高度:100%; then give the wrap the style of overflow: hidden;然后给包装样式溢出:隐藏; height: 100%;高度:100%; position: absolute; position:绝对;

lastly you need to scroll it so it's at the bottom.最后,您需要滚动它,使其位于底部。

document.getElementsByClassName("wrap")[0].scrollTop = document.getElementsByClassName("wrap")[0].scrollHeight

and there you have it:)你有它:)

test case here: http://jsbin.com/eguhuj#html此处的测试用例: http://jsbin.com/eguhuj#html

there is a tiny bit of scroll bar, but that's because of jsbin.有一点滚动条,但那是因为 jsbin。 in just an html document it looks perfect.在 html 文档中,它看起来很完美。

EDIT: updateed code... can we test this to see if it works first... can you put this in your anchor element?编辑:更新的代码......我们可以测试一下它是否首先工作......你可以把它放在你的锚元素中吗?

onclick="(function(){var blah = document.getElementsByClassName("wrap")[0];
document.getElementsByClassName("wr")[0].style.position = "absolute";
var meh = document.body.scrollTop;
blah.style.overflow = "hidden";
blah.style.height = "100%";
blah.style.position = "absolute";
blah.scrollTop = meh;})();"

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

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