duanpo1821 2017-07-22 13:56
浏览 53

当我用jquery动态点击按钮时,如何在页面上的特定位置创建聊天框

i want this enter image description here

but this working like enter image description here It create but it is appear bottom on page I need to scroll down to reach it.. I want that it appear on the page that is display on the screen

following is my code

var div = $("<div>", {
  // "text":"I'm a new paragraph!",
  "class": "bat",
  "css": {
    "background": "#f7f7f7",
    "height": "350",
    "border": "10px solid #33A919",
    "width": "250px",
    "float": "right",
    "position": "relative",
    "top": "20vh",
    "border-top-left-radius": "10px",
    "border-top-right-radius": "10px"
  }
});
$("body").append(div);

$("<div>", {
  "class": "foo",
  "text": "Heading my name is khan",
  "css": {
    "color": "white",
    "background": "#33A919",
    "height": "30px",
    "line-height": "30px"
  }

}).appendTo(".bat");

$(".foo").after("<div class='msg' style='background: hotpink;height:250px;width: 250px;overflow-y: auto;'></div>");
$(".msg").after("<textarea placeholder='Type your message here!' style='background: white; height: 65px; width: 250px; margin-top: 4px;'></textarea>");

}
  • 写回答

1条回答 默认 最新

  • dreamice2013 2017-07-22 14:24
    关注

    use position:fixed

    "position": "fixed",
    "bottom": "0",
    "right": "0",
    

    Demo

    var div = $("<div>", {
      // "text":"I'm a new paragraph!",
      "class": "bat",
      "css": {
        "background": "#f7f7f7",
        "height": "350",
        "border": "10px solid #33A919",
        "width": "250px",
        "float": "right",
        "position": "fixed",
        "bottom": "0",
        "right": "0",
        "border-top-left-radius": "10px",
        "border-top-right-radius": "10px"
      }
    });
    $("body").append(div);
    
    $("<div>", {
      "class": "foo",
      "text": "Heading my name is khan",
      "css": {
        "color": "white",
        "background": "#33A919",
        "height": "30px",
        "line-height": "30px"
      }
    
    }).appendTo(".bat");
    
    $(".foo").after("<div class='msg' style='background: hotpink;height:250px;width: 250px;overflow-y: auto;'></div>");
    $(".msg").after("<textarea placeholder='Type your message here!' style='background: white; height: 65px; width: 250px; margin-top: 4px;'></textarea>");
    body{height:800px}
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题