jquery - div 聊天总是在最前面

标签 jquery html css

我正在页面按钮上构建一个简单的聊天。 当我点击打开聊天时,它会将样式更改为更大的 div。 但我的问题是当我在页面上有 slider 时,聊天在 slider 后面。 我的问题是如何使 div 聊天始终位于顶部。

我的CSS:

.chat {
    position:fixed;
    right:0px;
    bottom:0px;
    height:24px;
    width:400px;
}
.active {
    position:fixed;
    right:0px;
    bottom:0px;
    height:424px;
    width:400px;
}
.head {
    background:#7f8c8d;
    padding-left: 3px;
    border-radius: 3px;
    color: #2c3e50;
    font-weight: bold;
}
.button {
    position:absolute;
    right:0px;
    cursor: pointer;
}
.conversation {
    background:white;
    width: 400px;
    height: 600px;
}

chat.php

<div class="chat" id="chat">
    <div class="head">
        <img src="img/chat/chat.png" alt="">&nbsp;Chat
        <img src="img/chat/open.png" alt="" class="button">
    </div>
    <div class="conversation">
        conversations here
    </div>
</div>
<script>
    $(document).ready(function() {
        var closed = true;
        $(".button").click(function() {
            if (closed) {
                $("#chat").attr('class', 'active');
                closed = false;
            }
            else {
                $("#chat").attr('class', 'chat');
                closed = true;
            }
        });
    });
</script>

最佳答案

设置始终保持在幻灯片顶部的 z-index

chat {
    position:fixed;
    right:0px;
    bottom:0px;
    height:24px;
    width:400px;
    z-index: 999999;
}

关于jquery - div 聊天总是在最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21748754/

相关文章:

javascript - 如何通过 javascript 或 jquery 中的输入赋予 css 属性来重新创建元素

jquery - jquery UI 自动完成的打字问题

javascript - 单击功能在我的 Web 应用程序中不起作用

javascript - jQuery 队列不起作用

html - 下拉对齐

javascript - 在 Twitter Bootstrap 主题之间切换?

html - CSS 选择器 : applying :focus on navbar

javascript - Bootstrap 模态切换

html - 将两个表格垂直对齐,其中一个表格充当另一个表格的标题

html - 知道为什么这两个盒子会偏移吗?