简体   繁体   English

Fancybox使用jQuery-Chosen时内容大小错误?

[英]Fancybox is getting the content size wrong when using jQuery-Chosen?

I have a Fancybox popup that uses AJAX to fetch content. 我有一个使用AJAX提取内容的Fancybox弹出窗口。

The fetched html is a div, containing a title, a table with input fields, and some buttons. 提取的html是div,包含标题,带有输入字段的表和一些按钮。

Problem is, I'm getting extra padding, or too small size; 问题是,我得到了多余的填充物,或者尺寸太小; anyways I have unnecessary scrollbars. 无论如何,我有不必要的滚动条。 I can disable them completely using CSS's overflow , or Fancybox's scrolling property, but I don't want them disabled completely - only added when necessary. 我可以使用CSS的overflow或Fancybox的scrolling属性完全禁用它们,但我不希望完全禁用它们-仅在必要时添加。

I'm using the jQuery Chosen Plugin, which is what's causing the overflow; 我正在使用jQuery Chosen插件,这是导致溢出的原因。 how can I avoid this? 我该如何避免呢?

The div content is modified by the client, as they can add/remove rows dynamically - so I need the scrollbars to appear in case the user adds too many rows to fit on screen. div内容由客户端修改,因为它们可以动态添加/删除行-因此,如果用户添加的行太多而无法容纳在屏幕上,则需要滚动条出现。 Here's what happens so far: 到目前为止发生的事情是:

滚动条

What's wrong with this? 这怎么了 Here's my CSS for the thing: 这是我的CSS:

#filter-form {
    width: 550px;
}
#filter-form h2 {
    text-align: center;
}
#filter-form .chzn-results {
    max-height: 110px;
}
#filter-form .buttons {
    margin-top: 10px;
    overflow: hidden;
}
#filter-form .buttons .btn_save_filter {
    float: right;
}
#assoc-num, #assoc-string {
    display: none;
}

#filter-form #CustomUserFilters_title {
    width: 350px;
    display: block;
    margin: 0 auto 30px;
}
#add-new-row td {
    text-align: right;
}
#add-new-row button {
    display: inline;
}
#filter-rules, #filter-form .buttons {
    width: 500px;
    margin: 0 auto;
}
#filter-rules td {
    width: 25% !important;
}

The width settings don't matter - removing them or increasing them both still cause them - so it's not Fancybox's autosize feature that's thinking the content is smaller -- it always resizes just the amount it needs, minus some pixels which cause the overflow. 宽度设置无关紧要-删除它们或增加它们都仍然会导致它们-所以并不是Fancybox的自动调整大小功能会认为内容较小-它总是调整大小只是所需的大小, 减去一些导致溢出的像素。

Here's the HTML (big mess, I know): 这是HTML(我知道很乱):

<div id="filter-div">
<form action="/customUserFilters/create" id="filter-form">
<h2>Create Filter</h2>
<input placeholder="Filter name" type="text" value="" name="CustomUserFilters[title]" id="CustomUserFilters_title"><table id="filter-rules">
    <tbody><tr class="filter-row">
<td class="td-bool-op"></td>
<td class="td-field-id"><select id="" style="width: 150px;" name="CustomUserFilterSettings[][field_id]">
<option value="2">Name</option>
</select></td>
<td class="td-assoc"><select style="width: 100px;" name="CustomUserFilterSettings[][assoc]">
<option value="=">=</option>
</select></td>
<td class="td-value"><input type="text" value="" name="CustomUserFilterSettings[][value]" id="CustomUserFilterSettings_value"></td></tr>    <tr id="new-filter">

<td class="td-bool-op"><select id="" style="width: 60px;" name="CustomUserFilterSettings[][bool_op]">
<option value="AND" selected="selected">AND</option>
<option value="OR">OR</option>
</select></td>
<td class="td-field-id"><select id="" style="width: 150px;" name="CustomUserFilterSettings[][field_id]">
<option value="2">Name</option>
</select></td>
<td class="td-assoc"><select style="width: 100px;" name="CustomUserFilterSettings[][assoc]">
<option value="=">=</option>
</select></td>
<td class="td-value"><input type="text" value="" name="CustomUserFilterSettings[][value]" id="CustomUserFilterSettings_value"></td>    </tr>
    <tr id="add-new-row">
        <td colspan="4">
            <button id="add-new-row-button" class="btn_grey" name="yt0" type="button">+ Add Another Condition</button>        </td>
    </tr>
</tbody></table>
<div class="buttons">
    <button class="btn_orange btn_save_filter" name="yt1" type="button">Create Filter</button>    <button class="btn_grey btn_cancel_filter" name="yt2" type="button">← Cancel</button></div>
</form>

And here's the Fancybox init: 这是Fancybox的初始化:

$('#new_filter_button').fancybox({
    beforeLoad: function() {
        $('.qtip').hide();
    },
    type: 'ajax',
    href: window.baseUrl + '/customUserFilters/create',
    openEffect: 'fade',
    closeEffect: 'fade',
    wrapCSS: 'filters-box'
});

Well, as it turns out, Fancybox hides overflowing content. 好吧,事实证明, Fancybox隐藏了溢出的内容。

Since I was using the jQuery Chosen Plugin , even when the boxes were closed, their containers were still in the page only hidden - this caused the div to be higher than it should, but for some reason Fancybox didn't just cause the dialog to be bigger, because the dropdown was hidden, it for some reason excluded it out of the height although it was still taking up vertical space. 因为我使用的是jQuery Chosen插件 ,所以即使关闭了框,它们的容器仍只在页面中隐藏-这导致div高于其应有的水平,但是由于某些原因,Fancybox不仅导致对话框更大,因为下拉菜单是隐藏的,因此出于某种原因将其排除在高度之外,尽管它仍占用垂直空间。 Then the horizontal scrollbar took width from the dialog and caused the width to overflow, which is what caused the vertical scrollbar. 然后,水平滚动条占据了对话框的宽度,并导致宽度溢出,这就是垂直滚动条的原因。

Damn! 该死的! Hopefully this answer will help other people running into this problem 希望这个答案可以帮助其他人遇到这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM