Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 将html宽度设置为宽度减去滚动条_Jquery_Scrollbar - Fatal编程技术网

Jquery 将html宽度设置为宽度减去滚动条

Jquery 将html宽度设置为宽度减去滚动条,jquery,scrollbar,Jquery,Scrollbar,我有一个网站的问题,滚动条是由各种模态禁用,导致网站的百分比改变时,模态是活跃的 在没有滚动条的情况下,如何使用html宽度对站点进行编码以生成整个布局?然后,当模式处于活动状态时,将不会重新计算CSS 以下是我使用的代码: $(function() { $("html").css({ "width": outerWidth() }); }); 但是我认为语法有问题…您必须告诉jQuery您想要

我有一个网站的问题,滚动条是由各种模态禁用,导致网站的百分比改变时,模态是活跃的

在没有滚动条的情况下,如何使用
html
宽度对站点进行编码以生成整个布局?然后,当模式处于活动状态时,将不会重新计算CSS

以下是我使用的代码:

        $(function() {
            $("html").css({
            "width": outerWidth()
          });
        });

但是我认为语法有问题…

您必须告诉jQuery您想要的
outerWidth()
是什么。在这种情况下,我们可以使用
$(this)
,因为您已经在上面一行中使用了
$(“html”)

$(function() {
    $("html").css({
        "width": $(this).outerWidth()
    });
});

body
innerWidth
不包括滚动条的宽度,但
outerWidth
包括:

$('body').innerWidth();
找到了一个解决方案

我为标题定义了一个100%的
外径的包装器,然后在其中放置一个相对元素。如果没有包装器,并使用数学(80%*
outerWidth
)确定头的宽度,但不确定jQuery语法,则会更干净

$(function() {
$("html").css({
    "width": $(this).outerWidth()
});
$("#header-outer").css({
    "width": $(this).outerWidth()
});
使用
.outerWidth()
包含滚动条的宽度:

$('body').innerWidth();

这是可行的,但是
position:fixed
元素仍然根据屏幕大小计算CSS百分比,而不是
html
宽度。如何强制固定位置元素从
html
元素获取父级大小@NoahWetjen@univers_你能解释一下你的确切意思吗?因为我想我不明白你的意思?请注意,header元素在modal open上更改了宽度。也许我可以使用jQuery定义标题@NoahWetjen@univers_但是您仍然希望滚动条消失,或者如果它只是停留在那里就可以了吗?当模式激活时,
html
元素上的背景滚动优先消失@诺哈维特仁