严格的流体布局| jQuery 插件

发布于 2024-12-23 18:36:13 字数 2345 浏览 1 评论 0原文

查看 jsFiddle 或者 查看 JS Bin

我今天有了这个想法,可以结合流体和固定宽度布局,并且还可以使响应式布局更快建造。它还将使布局中百分比的使用效果更好。

为此,我使用了与无框架网格系统类似的想法。

“逐列调整,而不是逐像素调整。”

我没有使用列,而是一次调整 1 个单位 的大小。 示例 jsFiddle 一次调整 10px,该示例展示了这如何带来好处在使用百分比时。它通过将 @media 样式与 max-widthmin-width 结合使用来实现此目的。

我遇到的问题是,您很快就会有很多 @media 样式,并且您必须手动输入每一个样式。所以我想它可以只使用一个相当简单的 jQuery 插件。然而,我对 jQuery 的了解有限,所以我对如何做到这一点只有一个模糊的想法,我已经在 jsFiddle

查看 jsFiddle 或者 查看 JS Bin

以下是一些 CSS @media 样式:

@media only screen and (max-width: 249px) {.test.two {width: 240px}}
@media only screen and (max-width: 259px) and (min-width: 250px) {.test.two {width: 250px}}
...
@media only screen and (max-width: 1259px) and (min-width: 1250px) {.test.two {width: 1250px}}
@media only screen and (min-width: 1260px) {.test.two {width: 1260px}}

以及映射出来的jQuery 小提琴

$('.test.two').strictfluid(10px 240px 1260px); // Apply function

var resizeEvery = 'first (10px)';
var minWidth = 'second (240px)';
var maxWidth = 'third (1260px)';

var calculate = minWidth;

// First @media :
"@media only screen and (max-width: " + (min-width + (resizeEvery - 1)) + " ) {" + min-width +"}}"

    calculate = calculate + resizeEvery;

// Middle @media's (Repeat While {calculate < maxWidth})
"@media only screen and (max-width: " + (calculate + (resizeEvery - 1)) + " ) and (min-width: " + (calculate) + " ) {" + (calculate) +"}}"

    calculate = calculate + resizeEvery;

// Last @media : 
"@media only screen and (min-width: " + (max-width) + " ) {" + max-width +"}}"

查看 jsFiddle 或者 查看 JS Bin

View jsFiddle
or
View JS Bin

I had this idea today that could combine both Fluid and Fixed width layouts and also make responsive layouts faster to build. It would also make the use of percentages in layouts work better.

To do this I'm using a similar idea to the Frameless Grid system.

"Adapt column by column, not pixel by pixel."

Rather than using columns, I'm adjusting the size 1 unit at a time. The example jsFiddle adjusts 10px at a time, the example shows how this could be beneficial in using percentages. It does this by using @media styles with max-width and min-width.

The problem I have run into is that you quickly have a lot of @media styles, and you would have to manually enter every single one. So I figured it could just use a fairly simple jQuery plugin. However, I have a limited knowledge of jQuery so I have only a vague idea of how this would be done which I have mapped out in the jsFiddle.

View jsFiddle
or
View JS Bin

Here is some of the CSS @media styles:

@media only screen and (max-width: 249px) {.test.two {width: 240px}}
@media only screen and (max-width: 259px) and (min-width: 250px) {.test.two {width: 250px}}
...
@media only screen and (max-width: 1259px) and (min-width: 1250px) {.test.two {width: 1250px}}
@media only screen and (min-width: 1260px) {.test.two {width: 1260px}}

And the mapped out jQuery Fiddle

$('.test.two').strictfluid(10px 240px 1260px); // Apply function

var resizeEvery = 'first (10px)';
var minWidth = 'second (240px)';
var maxWidth = 'third (1260px)';

var calculate = minWidth;

// First @media :
"@media only screen and (max-width: " + (min-width + (resizeEvery - 1)) + " ) {" + min-width +"}}"

    calculate = calculate + resizeEvery;

// Middle @media's (Repeat While {calculate < maxWidth})
"@media only screen and (max-width: " + (calculate + (resizeEvery - 1)) + " ) and (min-width: " + (calculate) + " ) {" + (calculate) +"}}"

    calculate = calculate + resizeEvery;

// Last @media : 
"@media only screen and (min-width: " + (max-width) + " ) {" + max-width +"}}"

View jsFiddle
or
View JS Bin

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文