代码之家  ›  专栏  ›  技术社区  ›  Miomir Dancevic

在引导程序3中添加侧边栏聊天?

  •  0
  • Miomir Dancevic  · 技术社区  · 10 年前

    我正在尝试为boostrap 3制作侧边栏聊天,类似这样

    enter image description here

    始终位于右侧,当单击从右向左打开时,

    enter image description here

    当打开用户clikc时,我不需要样式,我可以稍后修改css,只需要功能

    有人能帮我做一些基本的功能吗?

    这是我现在的东西

      <div class="row chat-window col-xs-5 col-md-3" id="chat_window_1" style="margin-left:10px;">
      <i id="chat-open" class="fa fa-camera-retro fa-2x"></i>
            <div class="col-xs-11 col-md-11 pull-right">
                <div class="panel panel-default">
                    <div class="panel-heading top-bar">
                        <div class="col-md-8 col-xs-8">
                            <h3 class="panel-title"><span class="glyphicon glyphicon-comment"></span> Chat - Miguel</h3>
                        </div>
                        </div>
                    <div class="panel-body msg_container_base">
                        <div class="row msg_container base_sent">
                            <div class="col-md-10 col-xs-10">
                                <div class="messages msg_sent">
                                    <p>that mongodb thing looks good, huh?
                                    tiny master db, and huge document store</p>
                                    <time datetime="2009-11-13T20:00">Timothy • 51 min</time>
                                </div>
                            </div>
                            <div class="col-md-2 col-xs-2 avatar">
                                <img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive ">
                            </div>
                        </div>
                        <div class="row msg_container base_receive">
                            <div class="col-md-2 col-xs-2 avatar">
                                <img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive ">
                            </div>
                            <div class="col-md-10 col-xs-10">
                                <div class="messages msg_receive">
                                    <p>that mongodb thing looks good, huh?
                                    tiny master db, and huge document store</p>
                                    <time datetime="2009-11-13T20:00">Timothy • 51 min</time>
                                </div>
                            </div>
                        </div>
                        <div class="row msg_container base_receive">
                            <div class="col-md-2 col-xs-2 avatar">
                                <img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive ">
                            </div>
                            <div class="col-xs-10 col-md-10">
                                <div class="messages msg_receive">
                                    <p>that mongodb thing looks good, huh?
                                    tiny master db, and huge document store</p>
                                    <time datetime="2009-11-13T20:00">Timothy • 51 min</time>
                                </div>
                            </div>
                        </div>
                        <div class="row msg_container base_sent">
                            <div class="col-xs-10 col-md-10">
                                <div class="messages msg_sent">
                                    <p>that mongodb thing looks good, huh?
                                    tiny master db, and huge document store</p>
                                    <time datetime="2009-11-13T20:00">Timothy • 51 min</time>
                                </div>
                            </div>
                            <div class="col-md-2 col-xs-2 avatar">
                                <img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive ">
                            </div>
                        </div>
                        <div class="row msg_container base_receive">
                            <div class="col-md-2 col-xs-2 avatar">
                                <img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive ">
                            </div>
                            <div class="col-xs-10 col-md-10">
                                <div class="messages msg_receive">
                                    <p>that mongodb thing looks good, huh?
                                    tiny master db, and huge document store</p>
                                    <time datetime="2009-11-13T20:00">Timothy • 51 min</time>
                                </div>
                            </div>
                        </div>
                        <div class="row msg_container base_sent">
                            <div class="col-md-10 col-xs-10 ">
                                <div class="messages msg_sent">
                                    <p>that mongodb thing looks good, huh?
                                    tiny master db, and huge document store</p>
                                    <time datetime="2009-11-13T20:00">Timothy • 51 min</time>
                                </div>
                            </div>
                            <div class="col-md-2 col-xs-2 avatar">
                                <img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive ">
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer">
                        <div class="input-group">
                            <input id="btn-input" type="text" class="form-control input-sm chat_input" placeholder="Write your message here..." />
                            <span class="input-group-btn">
                            <button class="btn btn-primary btn-sm" id="btn-chat">Send</button>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    

    CSS格式

    .panel{
        margin-bottom: 0px;
    }
    .chat-window{
        top:300px;
        position:fixed;
        float:right;
        margin-left:10px;
        right: -417px;
    }
    .chat-window > div > .panel{
        border-radius: 5px 5px 0 0;
    }
    .icon_minim{
        padding:2px 10px;
    }
    .msg_container_base{
      background: #e5e5e5;
      margin: 0;
      padding: 0 10px 10px;
      max-height:300px;
      overflow-x:hidden;
    }
    .top-bar {
      background: #666;
      color: white;
      padding: 10px;
      position: relative;
      overflow: hidden;
    }
    .msg_receive{
        padding-left:0;
        margin-left:0;
    }
    .msg_sent{
        padding-bottom:20px !important;
        margin-right:0;
    }
    .messages {
      background: white;
      padding: 10px;
      border-radius: 2px;
      box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
      max-width:100%;
    }
    .messages > p {
        font-size: 13px;
        margin: 0 0 0.2rem 0;
      }
    .messages > time {
        font-size: 11px;
        color: #ccc;
    }
    .msg_container {
        padding: 10px;
        overflow: hidden;
        display: flex;
    }
    img {
        display: block;
        width: 100%;
    }
    .avatar {
        position: relative;
    }
    .base_receive > .avatar:after {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        width: 0;
        height: 0;
        border: 5px solid #FFF;
        border-left-color: rgba(0, 0, 0, 0);
        border-bottom-color: rgba(0, 0, 0, 0);
    }
    
    .base_sent {
      justify-content: flex-end;
      align-items: flex-end;
    }
    .base_sent > .avatar:after {
        content: "";
        position: absolute;
        bottom: 0;
        left: 0;
        width: 0;
        height: 0;
        border: 5px solid white;
        border-right-color: transparent;
        border-top-color: transparent;
        box-shadow: 1px 1px 2px rgba(black, 0.2); // not quite perfect but close
    }
    
    .msg_sent > time{
        float: right;
    }
    
    
    
    .msg_container_base::-webkit-scrollbar-track
    {
        -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
        background-color: #F5F5F5;
    }
    
    .msg_container_base::-webkit-scrollbar
    {
        width: 12px;
        background-color: #F5F5F5;
    }
    
    .msg_container_base::-webkit-scrollbar-thumb
    {
        -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
        background-color: #555;
    }
    
    .visible{
      right:0px !important;
    }
    

    我需要的是隐藏右边的聊天,当点击图标显示聊天时,再点击图标隐藏?

    这里是 JS文件

    $( "#chat-open" ).click(function() {
    $('#chat_window_1').toggleClass('visible');
    });
    

    问题是,这种方式只会弹出聊天窗口,是否可以从右到左添加类似的幻灯片动画?

    这里是工作靴 http://www.bootply.com/ZTdXhZGi1d

    溶液

    $("#chat-open").click(function() {
      if ($('#chat_window_1').css('right') == "0px") {
        $('#chat_window_1').animate({right: "-417px"}, 1200);
      } else {
        $('#chat_window_1').animate({right: "0px"}, 1200);
      }
    });
    
    2 回复  |  直到 10 年前
        1
  •  1
  •   Cas Bloem    10 年前

    你应该使用 position:fixed 第。

    使用jQuery,可以设置div固定位置的动画。

    #chat {
      position:fixed;
      right:10px;
      top:20px;
      height:300px
    }
    

    还有一些jQuery:

    $("#chat").click(function() {
      if ($(this).css('right') == "200px") {
        $(this).animate({right: "10px"}, 1200);
      } else {
        $(this).animate({right: "200px"}, 1200);
      }
    });
    

    在#chat div中,您可以放置另一个div,这样当您单击聊天本身时,该div不会关闭。

        2
  •  0
  •   Chris Pickford    10 年前

    尝试 this fiddle 并适应您的需求。

    CSS:

    #sidebar {
        position: fixed;
        top: 0;
        height: 100%;
        width: 100px;
        background-color: #ccf;
        right: -80px;
    }
    .visible {
        right: 0px !important;
    }
    

    JS文件:

    $('#sidebar').click(function() {
        $(this).toggleClass('visible');
    });
    

    编辑: 包括之后 jQueryUI 在页面中,可以通过向 toggleClass() 功能:

    $(this).toggleClass('visible', 500);