1
function allowscroll()
{
if (screen.width<1200){document.getElementById('html').style.cssText='overflow-x: scroll !important;';};
}

<body onLoad="allowscroll();">

您好,上面的代码适用于任何元素,例如将“html”替换为“wrapper”,但是如何编辑应用于 html 的 css?基本上,由于溢出:隐藏在 ie7 中没有继承 - 这会导致右侧空白和水平滚动条很大(仅在 ie7 中,即 8 兼容),我将 css 设置为

html {overflow-x:hidden;}

这是在不丢失必要功能的情况下修复它的唯一方法,例如溢出的图形可见性。

这一切都很好,但是,较低的屏幕分辨率需要水平滚动才能看到所有页面本身,所以我正在尝试为这些用户恢复水平滚动条 - 并为发生的任何人恢复大右边距例如 ie7 1024 by 768 - 我可以忍受(除非有人碰巧有一个 superdupa 解决方案)。

document.getElementById('html').style.cssText='overflow-x: scroll !important;';

因此,上面的代码适用于编辑任何元素的 CSS,但不适用于 html 的 CSS。

我也试过:

function allowscroll()
{
if (screen.width<1200){document.getElementByName('html').style.cssText='overflow-x: scroll !important;';};
}

function allowscroll()
{
if (screen.width<1200){window.style.cssText='overflow-x: scroll !important;';};
}

我真的很感激任何帮助, - 如果它有助于查看解决方案,则适用的链接是:喜悦设计,基本上,它是如何取出的:

html {overflow-x:hidden;}

在较低的屏幕分辨率下从css...

非常感谢

将要

4

3 回答 3

2

有很多不同的方法来获取html元素:

document.documentElement
document.getElementsByTagName('html')[0]
document.body.parentNode

但老实说,必须有更好的方法。我现在没有时间追查这里到底发生了什么,但据我所知,添加position:relative溢出可能会有所帮助。

于 2011-02-03T16:47:18.790 回答
2

只需使用documentElement

document.documentElement

它有完整的浏览器支持

于 2011-02-03T16:43:23.370 回答
2

尝试document.getElementsByTagName("html")[0]

注意我刚刚编辑了答案,因为 getElementsByTagName 返回一个数组。您想要该数组中的第一个元素。

于 2011-02-03T16:37:28.363 回答