Advertisement
Guest User

MediaVida Chat Demo

a guest
Sep 21st, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.61 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Chat demo</title>
  5.         <style type="text/css" media="screen">
  6.             #container, #chat_messages, #chat_input {
  7.                 width: 100%;
  8.             }
  9.            
  10.             #container {
  11.                 height: 400px;
  12.             }
  13.            
  14.             #chat_messages {
  15.                 width: 90%;
  16.                 height: 95%;
  17.                 border: 1px solid #fa0;
  18.                 border-radius: 5px;
  19.                 padding: 10px;
  20.                 overflow: auto;
  21.             }
  22.            
  23.             #chat_input {
  24.                 height: 5%;
  25.             }
  26.            
  27.             #send {
  28.                 font-size: 1.4em;
  29.             }
  30.            
  31.             #chat_messages ul, #chat_messages li {
  32.                 list-style: none;
  33.                 margin: 0px;
  34.                 padding: 0px;
  35.             }
  36.            
  37.             #message {
  38.                 width: 75%;
  39.                 font-size: 1.4em;
  40.                 margin-top: 15px;
  41.             }
  42.         </style>
  43.     </head>
  44.     <body>
  45.         <div id="container">
  46.             <div id="chat_messages">
  47.                 <ul>
  48.                     <li><strong>Braubrau:</strong> Testing...</li>
  49.                     <li><strong>Braubrau:</strong> Testing...</li>
  50.                     <li><strong>Braubrau:</strong> Testing...</li>
  51.                     <li><strong>Braubrau:</strong> Testing...</li>
  52.                     <li><strong>Braubrau:</strong> Testing...</li>
  53.                     <li><strong>Braubrau:</strong> Testing...</li>
  54.                     <li><strong>Braubrau:</strong> Testing...</li>
  55.                     <li><strong>Braubrau:</strong> Testing...</li>
  56.                     <li><strong>Braubrau:</strong> Testing...</li>
  57.                     <li><strong>Braubrau:</strong> Testing...</li>
  58.                     <li><strong>Braubrau:</strong> Testing...</li>
  59.                     <li><strong>Braubrau:</strong> Testing...</li>
  60.                     <li><strong>Braubrau:</strong> Testing...</li>
  61.                     <li><strong>Braubrau:</strong> Testing...</li>
  62.                     <li><strong>Braubrau:</strong> Testing...</li>
  63.                     <li><strong>Braubrau:</strong> Testing...</li>
  64.                     <li><strong>Braubrau:</strong> Testing...</li>
  65.                     <li><strong>Braubrau:</strong> Testing...</li>
  66.                     <li><strong>Braubrau:</strong> Testing...</li>
  67.                     <li><strong>Braubrau:</strong> Testing...</li>
  68.                     <li><strong>Braubrau:</strong> Testing...</li>
  69.                     <li><strong>Braubrau:</strong> Testing...</li>
  70.                     <li><strong>Braubrau:</strong> Testing...</li>
  71.                     <li><strong>Braubrau:</strong> Testing...</li>
  72.                     <li><strong>Braubrau:</strong> Testing...</li>
  73.                     <li><strong>Braubrau:</strong> Testing...</li>
  74.                     <li><strong>Braubrau:</strong> Testing...</li>
  75.                     <li><strong>Braubrau:</strong> Testing...</li>
  76.                     <li><strong>Braubrau:</strong> Testing...</li>
  77.                     <li><strong>Braubrau:</strong> Testing...</li>
  78.                 </ul>
  79.             </div>
  80.             <div id="chat_input">
  81.                 <form action="" method="post" id="submit_form" accept-charset="utf-8">
  82.                     <input type="hidden" name="author" value="John Doe" id="author" />
  83.                     <input type="text" name="message" value="" id="message" placeholder="Write your message here!" />
  84.                     <input type="submit" name="send" value="Send" id="send" />
  85.                 </form>
  86.             </div>
  87.         </div>
  88.        
  89.         <script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript" charset="utf-8"></script>
  90.         <script type="text/javascript" charset="utf-8">
  91.             $(document).ready(function() {
  92.                 var message_box = $('#chat_messages');
  93.                 var last_message = $('#chat_messages li:last');
  94.                
  95.                 function chatScroll() {
  96.                     var bottom_position = last_message.position().top;
  97.                    
  98.                     message_box.animate({
  99.                         scrollTop: bottom_position
  100.                     });
  101.                 }
  102.                
  103.                 function sendMessage() {
  104.                     var message = $('#message').val();
  105.                     var author = $('#author').val();
  106.                     $('#message').val('');
  107.                    
  108.                     message_box.append('<li><strong>' + author + ':</strong> ' + message + '</li>');
  109.                    
  110.                     chatScroll();
  111.                 }
  112.                
  113.                 $('#submit_form').submit(function() {
  114.                     sendMessage();
  115.                     return false;
  116.                 });
  117.                
  118.                 chatScroll();
  119.                 $('#message').focus();
  120.             })
  121.         </script>
  122.     </body>
  123. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement