如果元素溢出,则更改元素高度

发布于 2024-12-10 02:48:44 字数 791 浏览 0 评论 0原文

我正在使用 jQuery,并且有一个手风琴小部件。我动态地将内容放置在每个容器内。当我将新内容放入新控件中时,我希望手风琴能够增长(高度增加)。我的手风琴控件如下所示:

在此处输入图像描述

我将我的项目手风琴小部件初始化为:

$("#accordion").accordion({
                autoHeight: false,
                navigation: true,
                collapsible: true,
                fillSpace: true

            });

当我将 HTML 放入该手风琴中时Ajax 动态地你可以看到元素开始溢出。我不想看到滚动条。

所以我想到了这样的事情:

somehow with JavaScript see if an element on the dom is overflowing (has the scroll bar)

if it does then increase it's height by 10 px until it does not overflow. 

我知道我可以设置固定高度,但我不知道我将提前在每个手风琴中放置多少 html 内容。对于如何处理这个溢出问题,你们有什么建议?

编辑

如果我能用 CSS 解决这个问题那就太好了,因为我动态构建了手风琴小部件。

I am using jQuery and I have an accordion widget. I place content inside each container dynamically. I will like the accordion to grow (height increase) as I place new content inside a new control. My accordion control looks like:

enter image description here

I initialize my projects accordion widget as:

$("#accordion").accordion({
                autoHeight: false,
                navigation: true,
                collapsible: true,
                fillSpace: true

            });

As I place HTML inside that accordion with Ajax dynamically you can see that the elements start overflowing. I don't want to see the scroll bars.

So I was thinking of dong something like:

somehow with JavaScript see if an element on the dom is overflowing (has the scroll bar)

if it does then increase it's height by 10 px until it does not overflow. 

I know I can set a fix height but I don't know how much html content I will be placing in each accordion in advance. What do you guys suggest on how to deal with this overflowing issue?

EDIT

It will be nice if I could resolve this with CSS since I construct the accordion widget dynamically.

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

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

发布评论

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

评论(2

仙气飘飘 2024-12-17 02:48:44

添加内容后,调用;

$("#accordion").accordion( "resize" );

After you have added the content, call;

$("#accordion").accordion( "resize" );
星光不落少年眉 2024-12-17 02:48:44

我一直在努力,并且我已经:

function removeOverflow(element){
     var newHeight = $(element).height() + element.offsetHeight; 
    $(element).height(newHeight+"px")  // set the hight of the overflowing element
}

I been working on it and I have:

function removeOverflow(element){
     var newHeight = $(element).height() + element.offsetHeight; 
    $(element).height(newHeight+"px")  // set the hight of the overflowing element
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文