Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Chat</title>
  6. <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
  7. <script type="text/javascript">
  8. $(function() {
  9. window.chat = {
  10. id: 0,
  11. get: function(){
  12. $.getJSON( "c.php?get=true&id="+this.id, function(a) {
  13. if(a.per == 1){
  14. chat.id = a.id;
  15. chat.add(a);
  16. }
  17. });
  18. },
  19. add: function(a){
  20.  
  21. for (i = 0; i < a.message.length; i++) {
  22. var div = '<div id="chat" class="chat_'+a.message[i].id+'"><div style="width:55px;float:left;margin-left: 5px;"><div class="nome" title="'+a.message[i].data+'"><b>'+a.message[i].usuario+'</b>:</div></div><div style="width:100%;">'+a.message[i].message+'</div></div>';
  23. $("#add").prepend(div);
  24. }
  25. },
  26. send: function(data){
  27. $.get( "c.php?env=true&msg="+data);
  28. $("#text").val('');
  29. }
  30. }
  31. });
  32. $(document).ready(function(){
  33. $("#submt").click(function(e){
  34. e.preventDefault(e);
  35. msg = $("#text").val();
  36. if(msg == ''){
  37. alert("não pode fica vazio!");
  38. return false;
  39. }
  40. chat.send(msg);
  41. });
  42. });
  43. setInterval(function(){chat.get();}, 1000);
  44. </script>
  45. <link rel='stylesheet prefetch' href='http://fonts.googleapis.com/css?family=Roboto:300'>
  46. <style>
  47. #box_chat{
  48. z-index:9999;
  49. width: 350px;
  50. height: 310px;
  51. position:fixed;
  52. bottom: 0;
  53. background-color: #fff;
  54. right: 0;
  55. margin: 20px;
  56. border: 1px solid #ccc;
  57. }
  58. #box_chat .title{
  59. font-family: 'roboto';
  60. width: 100%;
  61. height: 35px;
  62. background-color: rgba(0,102,255,1);
  63. color: #fff;
  64. text-indent: 15px;
  65. line-height: 34px;
  66. }
  67. #box_chat .text{
  68. width: 100%;
  69. height: 230px;
  70. border: 1px solid #ccc;
  71. }
  72. #box_chat .sendtext{
  73. margin: 8px;
  74. }
  75. #box_chat .sendtext input[type=text]{
  76. padding: 5px;
  77. width: 267px;
  78. }
  79. #chat{
  80. width: 100%;
  81. height:14px;
  82. }
  83. </style>
  84. </head>
  85. <body onload="chat.get();">
  86. <div id="box_chat">
  87. <div class="title">Chat Global</div>
  88. <div class="text" style="overflow-y: scroll;">
  89. <div style="margin: 5px;"></div>
  90. <div id="add"></div>
  91. </div>
  92. <div class="sendtext">
  93. <form id="env" action="c.php?env=true" method="get">
  94. <input type="text" name="env" value="true" style="display:none;" />
  95. <input type="text" name="msg" id="text" placeholder="Oque quer dizer?"/>
  96. <input id="submt" type="submit" value="envia" />
  97. </form>
  98. </div>
  99. </div>
  100. </body>
  101. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement