Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<div class="instructions">
  <h1>Instructions:</h1>
  <p>1. Click on the white box next to the word "Send"</p>
  <p>2. Click on one of the messages that pops up, and press the blue "Send"</p>
  <p>3. See your message appear real-time on the watch screen in the next demo below</p>
</div>
<div class="iphone">
  <div class="camera"></div>  
  <div class="speaker"></div>
  <div class="screen">
    <div class="list">
    </div>
    <div class="input">
      <input type="text" readonly="readonly"/>
      <button>Send</button>
    </div>
  </div>
  <div class="home"></div>
</div>
<div class="options tooltip top" style="display: none;">
  <p>Do you want to go the movies?</p>
  <p>This blog is awesome, right?</p>
  <p>Do you like Firebase?</p>
</div>
<div class="clickhere tooltip left">Click Here</div>
              
            
!

CSS

              
                body {
  margin: 0;
}
.instructions {
  background-color: #222;
  position: fixed;
  width: 180px;
  height: 100%;
  color: #DDD;
  font-family: 'Roboto', sans-serif;
  padding: 20px;
}

.iphone {
  border: 2px solid #F9E7D4;
  border-radius: 25px;
  width: 195px;
  height: 375px; 
  box-shadow: 0 0 1px 1px #EEDDCA;
  background-color: #F5F5F5;
  position: relative;
  font-family: 'Roboto', sans-serif;
  left: 270px;
  top: 30px;
}

.camera {
  position: absolute;
  top: 16px;
  left:63px;
  width: 8px;
  height: 8px;
  background-color: black;
  border-radius: 50%;
}

.speaker {
  position: absolute;
  top: 18px;
  left: 80px;
  background-color: black;
  width: 35px;
  height: 4px;
  border-radius: 5px;
}

.screen {
  position: relative;
  width: 175px;
  height: 285px;
  border: 2px solid black;
  margin: 40px 8px;
  background-color: white;
}

.home {
  position: absolute;
  bottom: 10px;
  left: 85px;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: 2px solid #EEDDCA;
}

.list {
  position: absolute;
  top: 0;
  width: 100%;
  height: 256px;
  overflow: hidden;
}

.list .message {
  margin: 10px;
  padding: 10px;
  border-radius: 5px;
  font-size: .7em;
}

.list .message.left {
  background-color: lightgrey;
  margin-right: 50px;
}

.list .message.right {
  /*background-color: #2B90FA;
  color: white;*/
  background-color: lightgreen;
  margin-left: 50px;
}

.input {
  position: absolute;
  bottom: 0;
  width: 100%;
  background-color: lightgrey;
}

.input input {
  width: 60%;
  margin: 5px;
  cursor: pointer;
}

button {
  border: none;
  background: none;
  color: blue;
  cursor: pointer;
  border-radius: 5px;
}button:focus {
  outline: none;
}button:active {
  color: #333;
}

.clickhere {
  position: absolute;
  left: 120px;
  top: 325px;
  color: #FFFFFF;
  background: #3347FF;
}

.options {
  position: absolute;
  top: 145px;
  left: 290px;
  color: #000;
  background: lightgrey;
  border: 1px solid #3347FF;
  font-size: .9em;
}
.options p {
  cursor: pointer;
  border-radius: 5px;
  padding: 10px;
  margin: 0;
}.options p:hover {
  background-color: #AAA;
}

.tooltip.top:after {
  content: '';
  position: absolute;
  top: 100%;
  left: 30%;
  width: 0; height: 0;
  border-top: 8px solid #3347FF;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
}

.tooltip {
  width:140px;
  border-radius: 6px;
  z-index: 999;
  position: absolute;
  padding: 10px;
  font-family: 'Roboto', sans-serif;
}
.tooltip.left:after {
  content: '';
  position: absolute;
  top: 50%;
  left: 100%;
  margin-top: -8px;
  width: 0; height: 0;
  border-left: 8px solid #3347FF;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

              
            
!

JS

              
                //Initialize Firebase Connection
var myFirebaseRef = new Firebase("https://exampleapp1.firebaseio.com/demopen");

//Event handler for Firebase data changed (from any client)
myFirebaseRef.on('value', function(snapshot){
  $('.list').empty();
  //Loops through each child at this Firebase location
  snapshot.forEach(function(childSnapshot) {
    var child = childSnapshot.val();
    $('.list').append('<div id="'+childSnapshot.key()+'" class="message '+child.side+'">'+child.message+'</div>');
  });
  scrollDown();
});

//Jquery event handler to send message to firebase on click of the 'Send' button
$('button').on('click', function(e) {
  var msg = $('input').val();
  if (msg && msg.trim() != "") {
    //Send message to Firebase
    myFirebaseRef.push({
      message: msg,
      side: 'right'
    });
    //Clear input box
    $('input').val("");
  }
});

$('.options p').on('click', function(e) {
  var msg = $(this).text();
  $('input').val(msg);
  $(this).parent().hide();
});

//Helper method to scroll the phone screen down when a new message comes in
function scrollDown() {
  $('.list').scrollTop($('.list').get(0).scrollHeight);
}

$('.input input').on('click', function() {
  $('.clickhere').hide();
  $('.options').show();
});
              
            
!
999px

Console