简体   繁体   English

使用JavaScript隐藏IFRAME滚动条

[英]Hide IFRAME scrollbars with javascript

I have a jQuery project where I open an iframe with scrollbars (scrolling=auto) in an overlay (boxy plugin) popup with an animation. 我有一个jQuery项目,其中在带有动画的叠加(框式插件)弹出窗口中,使用滚动条(scrolling = auto)打开iframe。 When the overlay is closed I want the popup to tween and fade-out. 当覆盖层关闭时,我希望弹出窗口可以进行补间和淡出。 So far so good, but while the size of the iframe is decreasing, the scrollbars suddenly appear before the whole thing disappears. 到目前为止还算不错,但是当iframe的大小减小时,滚动条突然出现,然后整个事情消失了。

I tried manipulating the iframes scrolling attribute but that doesn't seem to exist on the iframes' DOM object at that point. 我尝试操纵iframe的滚动属性,但那时iframe的DOM对象上似乎还不存在这种属性。 Can anyone help? 有人可以帮忙吗?

No need for JavaScript. 无需JavaScript。 Just use the following CSS on the iframe: 只需在iframe上使用以下CSS:

overflow: hidden;

IIRC, the scrollbars belong to the framed page, and have to be disabled there. IIRC,滚动条属于框架页面,必须在此处禁用。 If your iframes are cross-domain, this may not be possible. 如果您的iframe是跨域的,则可能无法实现。

Frameless iframe with no scrollbars: 没有滚动条的无框架iframe:

 var el = document.createElement("iframe");
 var iframe_style = "overflow:hidden; margin:0;padding:0;"
 var ifattr = {
        id: 'my_iframe', width: '520', height: '300', 'scrolling': 'no', 'marginWidth':0,
        'marginHeight':0, 'noResize': 0, 'border': 0, 'frameBorder':0, 'frameSpacing':0,
        'background': 'transparent','allowTransparency': 'allowTransparency',
        'name' :'my_iframe','style':iframe_style};

 for (var i in ifattr) {
      el.setAttribute(i, ifattr[i]);
 }

This is pure JS, can be easily ported to jQuery with use of attr() , tested in IE6-8, FF. 这是纯JS,可以使用attr()轻松移植到jQuery,在IE6-8,FF中进行了测试。

Document inside should use: body {overflow: hidden;} - not tested if it's really required. 内部文档应使用:body {overflow:hidden;}-未经测试是否确实需要。

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

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