与分辨率无关的网站? (或者,“缩放整个网站以填充浏览器”)

发布于 2024-11-18 22:36:31 字数 692 浏览 2 评论 0原文

我正在开发一个真正受益于填充整个屏幕的项目——它本质上是一个 7000 像素长的页面,带有一个巨大的背景填充整个长度(可能被切成单独的部分,并在最终版本中以智能顺序方式加载) ),当您向下滚动时,有 5 或 6 个不同的片段/区域/幻灯片(基本上是“内容区域”)。

顶部是一个导航栏,填充了设计的整个水平宽度。在其下方的背景上,是一堆不同的元素,放置在背景上的特定位置。背景上的位置至关重要,因为每个元素都特定于页面的特定部分。

在我看来,它正在做类似 http://windyroad.org/2007 /05/18/resolution-independent-web-design/ 真的非常有用。唉,那是 2007 年的事了,看起来更像是一个概念验证。另外,每次有人调整浏览器窗口大小时,用 PHP 调整 1000x7000 像素图像的大小似乎是个坏主意(或者更糟糕的是,五个 1000x1000 图像!)。

我使用过 jQuery 脚本来缩放背景图像以填充整个浏览器,但从未遇到过任何缩放页面上每个元素的东西。

有没有办法动态缩放整个网站以适应浏览器窗口?

我很确定我已经知道答案,但我想我会把它扔在那里以防万一有人有想法。

非常感谢!

I'm working on a project that would really benefit from filling the whole screen -- it's essentially one 7000px-long page with a giant background filling the whole length (probably chopped into separate pieces and loaded in an intelligent sequential fashion in the final version), with 5 or 6 different segments/areas/slides (basically, "content areas") as you scroll down.

At the top is a navigation bar that fills the entire horizontal width of the design. Below it, on the background, are a bunch of different elements, placed at specific positions on the background. The placement on the background is critical as each element is specific to a certain section of the page.

It seems to me doing something like http://windyroad.org/2007/05/18/resolution-independent-web-design/ would be really really useful. Alas, that's from 2007 and seems more like a proof-of-concept than anything. Plus it seems like a bad idea to resize a 1000x7000px image with PHP every time somebody resizes their browser window (Or even worse, five 1000x1000 images!).

I've used jQuery scripts that scale a background image to fill the entire browser, but never ran across anything that scales every element on page.

Is there any way to dynamically scale an entire website to fit the browser window?

I'm pretty sure I already know the answer, but figured I'd toss it out there just in case somebody has an idea.

Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白况 2024-11-25 22:36:31

该脚本还计算滚动条大小,如果需要。您将需要一个带有 wrapper id 的块(divspan 等)。

这是一个跨浏览器脚本,它支持所有现代浏览器。

我希望你喜欢它。放心使用!

// DONT FORGET TO ADD THIS TO YOUR WRAPPER'S CSS BLOCK
// THIS WILL KEEP YOUR SITE CENTERED
// IF YOU USE margin-left:auto; margin-right:auto;

// transform-origin: 50% 0%;
// -ms-transform-origin: 50% 0%;
// -moz-transform-origin: 50% 0%;
// -webkit-transform-origin: 50% 0%;
// -o-transform-origin: 50% 0%;

function FitToScreen(FitType)
{
    var Wrapper = document.getElementById('wrapper');

    var ScreenWidth = window.innerWidth;
    var ScreenHeight = window.innerHeight;

    var WrapperWidth = Wrapper.offsetWidth;
    var WrapperHeight = Wrapper.offsetHeight + 200;

    var WidthRatio = parseFloat(ScreenWidth/WrapperWidth);
    var HeightRatio = parseFloat(ScreenHeight/WrapperHeight);

    var ScaleRatio = 1.0;

    if (FitType == 'width')
    {
        ScaleRatio = WidthRatio;
        if(ScaleRatio * WrapperHeight > ScreenHeight)
        {
            ScaleRatio = parseFloat(ScreenWidth/(WrapperWidth + GetScrollBarWidth () -1));
        }
    }
    else if (FitType == 'height')
    {
        ScaleRatio = HeightRatio;
        if(ScaleRatio * WrapperWidth > ScreenWidth)
        {
            ScaleRatio = parseFloat(ScreenHeight/(WrapperHeight + GetScrollBarWidth () -1));
        }
    }

    var ScaleText = 'scale(' + ScaleRatio.toString().replace(',','.') + ')';

    //Chrome and Safari
        Wrapper.style.webkitTransform = ScaleText;
    //Firefox
        Wrapper.style.MozTransform = ScaleText;
    //Internet Explorer
        Wrapper.style.msTransform = ScaleText;
    //Opera
        Wrapper.style.OTransform = ScaleText;
    //Standard
        Wrapper.style.transform = ScaleText;
}

function GetScrollBarWidth ()
{
    var inner = document.createElement('p');
    inner.style.width = '100%';
    inner.style.height = '200px';

    var outer = document.createElement('div');
    outer.style.position = 'absolute';
    outer.style.top = '0px';
    outer.style.left = '0px';
    outer.style.visibility = 'hidden';
    outer.style.width = '200px';
    outer.style.height = '150px';
    outer.style.overflow = 'hidden';
    outer.appendChild (inner);

    document.body.appendChild (outer);
    var w1 = inner.offsetWidth;
    outer.style.overflow = 'scroll';
    var w2 = inner.offsetWidth;
    if (w1 == w2) w2 = outer.clientWidth;

    document.body.removeChild (outer);
    return (w1 - w2);
}

The script also calculate the scrollbar size if needed. You will need a block (div, span, etc...) with the wrapper id.

This is a cross-browser script, it supports all the modern browsers.

I hope you like it. Feel free to use!

// DONT FORGET TO ADD THIS TO YOUR WRAPPER'S CSS BLOCK
// THIS WILL KEEP YOUR SITE CENTERED
// IF YOU USE margin-left:auto; margin-right:auto;

// transform-origin: 50% 0%;
// -ms-transform-origin: 50% 0%;
// -moz-transform-origin: 50% 0%;
// -webkit-transform-origin: 50% 0%;
// -o-transform-origin: 50% 0%;

function FitToScreen(FitType)
{
    var Wrapper = document.getElementById('wrapper');

    var ScreenWidth = window.innerWidth;
    var ScreenHeight = window.innerHeight;

    var WrapperWidth = Wrapper.offsetWidth;
    var WrapperHeight = Wrapper.offsetHeight + 200;

    var WidthRatio = parseFloat(ScreenWidth/WrapperWidth);
    var HeightRatio = parseFloat(ScreenHeight/WrapperHeight);

    var ScaleRatio = 1.0;

    if (FitType == 'width')
    {
        ScaleRatio = WidthRatio;
        if(ScaleRatio * WrapperHeight > ScreenHeight)
        {
            ScaleRatio = parseFloat(ScreenWidth/(WrapperWidth + GetScrollBarWidth () -1));
        }
    }
    else if (FitType == 'height')
    {
        ScaleRatio = HeightRatio;
        if(ScaleRatio * WrapperWidth > ScreenWidth)
        {
            ScaleRatio = parseFloat(ScreenHeight/(WrapperHeight + GetScrollBarWidth () -1));
        }
    }

    var ScaleText = 'scale(' + ScaleRatio.toString().replace(',','.') + ')';

    //Chrome and Safari
        Wrapper.style.webkitTransform = ScaleText;
    //Firefox
        Wrapper.style.MozTransform = ScaleText;
    //Internet Explorer
        Wrapper.style.msTransform = ScaleText;
    //Opera
        Wrapper.style.OTransform = ScaleText;
    //Standard
        Wrapper.style.transform = ScaleText;
}

function GetScrollBarWidth ()
{
    var inner = document.createElement('p');
    inner.style.width = '100%';
    inner.style.height = '200px';

    var outer = document.createElement('div');
    outer.style.position = 'absolute';
    outer.style.top = '0px';
    outer.style.left = '0px';
    outer.style.visibility = 'hidden';
    outer.style.width = '200px';
    outer.style.height = '150px';
    outer.style.overflow = 'hidden';
    outer.appendChild (inner);

    document.body.appendChild (outer);
    var w1 = inner.offsetWidth;
    outer.style.overflow = 'scroll';
    var w2 = inner.offsetWidth;
    if (w1 == w2) w2 = outer.clientWidth;

    document.body.removeChild (outer);
    return (w1 - w2);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文