根据浏览器窗口的大小动态调整div大小

编程入门 行业动态 更新时间:2024-10-24 00:25:17
本文介绍了根据浏览器窗口的大小动态调整div大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想弄明白如何让div动态调整大小,基于浏览器窗口的大小。我设置了一个jsbin来说明我的问题,在这里: jsbin/uxomul

我想要做的是调整保存图像的div的大小,以便div总是填充浏览器窗口高度的左边(除了底部25px的边距,在身体上设置)。

这里有一个演示,可能说明我想要更清楚地实现: http ://emilolsson/shop/demo/layers

任何想法,最好的方法是什么?

解决方案

您可以这样做:

var width = $(window).width() - 25; $(#mydiv)。width(width);

25只是一个示例数字,例如您的保证金(您也可以动态获得) p>

您可能还想将其包装到一个函数中,并在页面加载和调整大小时调用此函数

I'm trying to figure out how to have a div dynamically resize, based on the size of the browser window. I've set up a jsbin that illustrates my problem, here: jsbin/uxomul

What I want to do is to resize the div that holds the images so that the div always fills what's left of the height of the browser window (except a 25px margin at the bottom, that's set on body).

Here's a demo that maybe illustrates what I want to achieve more clearly: emilolsson/shop/demo/layers

Any ideas what would be the best way to approach this?

解决方案

You can do something like this:

var width = $(window).width() - 25; $("#mydiv").width(width);

25 is just a sample number, for example your margin (you can get this dynamically too)

You may also want to wrap it into a function and call this on both page load and on resize

更多推荐

根据浏览器窗口的大小动态调整div大小

本文发布于:2023-10-08 01:49:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471163.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小   浏览器   窗口   动态   div

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!