【问题标题】:Jquery resize causes jumpJquery调整大小导致跳转
【发布时间】:2014-03-29 06:28:31
【问题描述】:

我使用 jQuery 在 <ul> 元素中创建了一组按钮。我现在正试图通过在其顶部添加一个句柄来调整 <ul> 的大小。问题是当我尝试调整<ul> 的大小时,它会像下图一样跳跃。为什么会发生这种情况。

调整大小之前

调整大小后

jQuery 用于生成元素:

function create_bar() {
        var table_container = $("<ul />", {
            class: "app_container_T t_ul ui-widget-content"
        });
        table_container.resizable({ handles: "n" });
            var row = $("<li />");
                var menu = $("<ul />", {
                    class: "menu_T t_ul"
                });
                    var section_1 = $("<li />");
                        var add_element_button = $("<button />", {
                            text: '+',
                            click: add_content_selection_element,
                            class: "large_menu_button_T"
                        });
                        section_1.append(add_element_button);                                      
                        /*Rest of the buttons are created and added in the same way*/
                    menu.append(section_1);
                row.append(menu);
            table_container.append(row);
        $('body').append(table_container);

CSS

.app_container_T {
    position:fixed;
    bottom:0;
    left:0;
    z-index: 998;
    background-color:grey;
    margin: 0;
    padding: 0;
}
.app_container_T > li {
    /*create a class for them to share itll be faster, like t_ul*/
    display: inline-block;
}
.t_ul {
    list-style: none;
}
.app_container_T * {
    box-sizing: border-box;
    border-radius:5px;
    vertical-align : text-bottom;
}
.menu_T {
    background-color:lightblue;
    padding: 0px;
    width:60px;
}
.large_menu_button_T {
    background: #0016f0;
    color: #ffffff;
    height: 50px;
    width: 50px;
    margin: 3px;
    font-size: 20px;
    border-radius:10px;
}
.ui-resizable-n {
    cursor: n-resize;
    width: 100%;
    top: 0px;
    left: 0;
    border-top: 5px solid #f00;
    z-index: 999;
}

生成的 HTML

<ul class="app_container_T t_ul ui-widget-content ui-resizable">
    <div class="ui-resizable-handle ui-resizable-n" style="z-index: 90; display: block;"></div>
    <li>
        <ul class="menu_T t_ul">
            <li>
                <button class="large_menu_button_T">+</button>
                <button class="large_menu_button_T">T</button>
                <button class="small_menu_button_T options">o</button>
            </li>
        </ul>
    </li>
</ul>

【问题讨论】:

    标签: jquery html css jquery-ui


    【解决方案1】:

    问题是您将底部属性固定为 0,因此当您调整它的大小或更改位置时会出现问题 bcoz 它更改为底部:0

    .app_container_T {
        position:fixed;
        bottom:0; ////// remove this then change top no problem
        left:0;
        z-index: 998;
        background-color:grey;
        margin: 0;
        padding: 0;
    }
    

    【讨论】:

    • 很抱歉,我不明白您的 jsfiddle 显示的内容。另外,如果我不能使用底部:0,我还能如何将
        保持在底部?
    • 我已经意识到这个问题。我需要我的元素保持在页面底部,并且将位置切换到绝对不会这样做。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 2014-08-25
    • 1970-01-01
    • 2014-10-08
    • 2014-01-21
    • 1970-01-01
    相关资源
    最近更新 更多