Chat-page

In this example below you will see how to do a Chat-page with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by mast-10, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright mast-10 ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Chat-page</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  
<html>
  <head>
    <!-- Required meta tags-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <!-- Your app title -->
    <title>Lifespace</title>
    <!-- Path to Framework7 iOS CSS theme styles-->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/framework7/1.6.5/css/framework7.material.min.css">
    <!-- Path to Framework7 iOS related color styles -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/framework7/1.6.5/css/framework7.material.colors.css">
    <!-- Path to your custom app styles-->
    <link rel="stylesheet" href="path/to/my-app.css">
    
        <!-- Path to your custom app icons -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet"> 
  </head>
  <body>
    <!-- Status bar overlay for full screen mode (PhoneGap) -->
    <div class="statusbar-overlay"></div>
    <!-- Panels overlay-->
    <div class="panel-overlay"></div>
    <!-- Left panel with reveal effect-->
    <div class="panel panel-left panel-reveal">
      <div class="content-block">
        <p>Left panel content goes here</p>
      </div>
    </div>
    <!-- Views -->
    <div class="views">
      <!-- Your main view, should have "view-main" class -->
      <div class="view view-main">
        <!-- Pages container, because we use fixed-through navbar and toolbar, it has additional appropriate classes-->
        <div class="pages navbar-fixed ">
          <!-- Page, "data-page" contains page name -->
          <div data-page="index" class="page">            
              <!-- Top Navbar-->
              <div class="navbar">
                <div class="navbar-inner">

                  <div class="left sliding">
<div class="item-media" style="margin-left:10px; margin-top:10px">
                      <img src="http://www.iconarchive.com/download/i102645/graphicloads/flat-finance/person.ico" width="44"></div>
                    <div class="item-inner" style="margin-left:10px">
                      <div class="item-title-row">
                        <div class="item-title" style="font-size:18px; line-height:23px">Nombre de usuario</div>
                      </div>
                      <div class="item-subtitle" style="font-size:14px; line-height:15px">En linea</div>
                    </div>
                    
                  </div>
                   
                  
                  <div class="right">
                    <!-- Right link contains only icon - additional "icon-only" class
                      Additional "open-panel" class tells app to open panel when we click on this link-->
                    <a href="#" class="link icon-only"><i class="material-icons">more_vert</i></a>
                  </div>
                </div>
              </div>          
            
              <!-- messagebar -->
  <div class="toolbar messagebar">
    <div class="toolbar-inner">
      <textarea placeholder="Escribir mensaje"></textarea><a href="#" class="link"><i class="material-icons color-blue">send</i></a>
    </div>
  </div>
            
              <div class="page-content messages-content">
 
<div class="messages">
      <div class="messages-date">Sunday, Feb 9 <span>12:58</span></div>
      <div class="message message-sent">
        <div class="message-text">Hello</div>
      </div>
      <div class="message message-sent">
        <div class="message-text">How are you?</div>
      </div>
      <div class="message message-received">
        <div class="message-name">Kate</div>
        <div class="message-text">I am fine, thanks</div>
        <div style="background-image:url(http://lorempixel.com/output/people-q-c-100-100-9.jpg)" class="message-avatar"></div>
      </div>
      <div class="messages-date">Sunday, Feb 3 <span>11:58</span></div>
      <div class="message message-sent">
        <div class="message-text">Nice photo?</div>
      </div>
      <div class="message message-sent message-pic">
        <div class="message-text"><img src="http://lorempixel.com/300/300/"></div>
        <div class="message-label">Delivered</div>
      </div>
      <div class="message message-received">
        <div class="message-name">Kate</div>
        <div class="message-text">Wow, awesome!</div>
        <div style="background-image:url(http://lorempixel.com/output/people-q-c-100-100-9.jpg)" class="message-avatar"></div>
      </div>
    </div>
                
                
    
              </div>
            

            
 </div>
        </div>
      </div>
    </div>
    <!-- Path to Framework7 Library JS-->
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/framework7/1.6.5/js/framework7.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/framework7/1.6.5/js/framework7.js"></script>
    <!-- Path to your app js-->
    <script type="text/javascript" src="path/to/my-app.js"></script>
  </body>
</html>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/mast-10/chat-page-zPervy */


.item-media {
  margin: auto;
}



/*Downloaded from https://www.codeseek.co/mast-10/chat-page-zPervy */
// Initialize app
var myApp = new Framework7({
   hideTabbarOnPageScroll: true,
   showBarsOnPageScrollEnd: true,
});

// If we need to use custom DOM library, let's save it to $$ variable:
var $$ = Dom7;
 
// Add view
var mainView = myApp.addView('.view-main', {
  // Because we want to use dynamic navbar, we need to enable it for this view:
  dynamicNavbar: true
});

// Conversation flag
var conversationStarted = false;
 
// Init Messages
var myMessages = myApp.messages('.messages', {
  autoLayout:true
});
 
// Init Messagebar
var myMessagebar = myApp.messagebar('.messagebar');
 
// Handle message
$$('.messagebar .link').on('click', function () {
  // Message text
  var messageText = myMessagebar.value().trim();
  // Exit if empy message
  if (messageText.length === 0) return;
 
  // Empty messagebar
  myMessagebar.clear()
 
  // Random message type
  var messageType = (['sent', 'received'])[Math.round(Math.random())];
 
  // Avatar and name for received message
  var avatar, name;
  if(messageType === 'received') {
    avatar = 'http://lorempixel.com/output/people-q-c-100-100-9.jpg';
    name = 'Kate';
  }
  // Add message
  myMessages.addMessage({
    // Message text
    text: messageText,
    // Random message type
    type: messageType,
    // Avatar and name:
    avatar: avatar,
    name: name,
    // Day
    day: !conversationStarted ? 'Today' : false,
    time: !conversationStarted ? (new Date()).getHours() + ':' + (new Date()).getMinutes() : false
  })
 
  // Update conversation flag
  conversationStarted = true;
});

Comments