Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Chat</title>
- <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
- <script type="text/javascript">
- $(function() {
- window.chat = {
- id: 0,
- get: function(){
- $.getJSON( "c.php?get=true&id="+this.id, function(a) {
- if(a.per == 1){
- chat.id = a.id;
- chat.add(a);
- }
- });
- },
- add: function(a){
- for (i = 0; i < a.message.length; i++) {
- 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>';
- $("#add").prepend(div);
- }
- },
- send: function(data){
- $.get( "c.php?env=true&msg="+data);
- $("#text").val('');
- }
- }
- });
- $(document).ready(function(){
- $("#submt").click(function(e){
- e.preventDefault(e);
- msg = $("#text").val();
- if(msg == ''){
- alert("não pode fica vazio!");
- return false;
- }
- chat.send(msg);
- });
- });
- setInterval(function(){chat.get();}, 1000);
- </script>
- <link rel='stylesheet prefetch' href='http://fonts.googleapis.com/css?family=Roboto:300'>
- <style>
- #box_chat{
- z-index:9999;
- width: 350px;
- height: 310px;
- position:fixed;
- bottom: 0;
- background-color: #fff;
- right: 0;
- margin: 20px;
- border: 1px solid #ccc;
- }
- #box_chat .title{
- font-family: 'roboto';
- width: 100%;
- height: 35px;
- background-color: rgba(0,102,255,1);
- color: #fff;
- text-indent: 15px;
- line-height: 34px;
- }
- #box_chat .text{
- width: 100%;
- height: 230px;
- border: 1px solid #ccc;
- }
- #box_chat .sendtext{
- margin: 8px;
- }
- #box_chat .sendtext input[type=text]{
- padding: 5px;
- width: 267px;
- }
- #chat{
- width: 100%;
- height:14px;
- }
- </style>
- </head>
- <body onload="chat.get();">
- <div id="box_chat">
- <div class="title">Chat Global</div>
- <div class="text" style="overflow-y: scroll;">
- <div style="margin: 5px;"></div>
- <div id="add"></div>
- </div>
- <div class="sendtext">
- <form id="env" action="c.php?env=true" method="get">
- <input type="text" name="env" value="true" style="display:none;" />
- <input type="text" name="msg" id="text" placeholder="Oque quer dizer?"/>
- <input id="submt" type="submit" value="envia" />
- </form>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement