I have problem with centering div element. I tried with marings (margin: o auto) and with left/right CSS atributes (left: 50%, right: 50%) but result was wrong. Can someone tell me where's the problem?
EDIT:
I am using JavaScript to fill content of "boxcard" div. Problem is that content of "boxcard" div is not aligned to center (it's aligned to left). I am using JavaScript code (added below) to fill DIV's content.
This is what I have:
EDIT 2:
Here is jsfiddle : jsfiddle
CSS:
* {
margin: 0;
padding: 0;
}
body {
font: 18px Verdana;
color: #FFF;
background: #CCC;
}
#picbox {
margin: 0px auto;
width: auto;
}
#boxcard {
z-index: 1;
margin: 0px auto;
width: auto;
}
#boxcard div{
float: left;
width: 100;
height: 120;
margin: 5px;
padding: 5px;
border: 4px solid #EE872A;
cursor: pointer;
border-radius: 10px;
box-shadow: 0 1px 5px rgba(0,0,0,.5);
background: #B1B1B1;
z-index: 2;
}
#boxcard > div:nth-child(6n+1) {
clear: both;
}
#boxcard div img {
display: none;
border-radius: 10px;
z-index: 3;
}
#boxbuttons {
text-align: center;
margin: 20px;
display: block;
}
#boxbuttons .button {
text-transform: uppercase;
background: #EE872A;
padding: 5px 10px;
margin: 5px;
border-radius: 10px;
cursor: pointer;
}
#boxbuttons .button:hover {
background: #999;
}
HTML
<div id="picbox">
<span id="boxbuttons">
<span class="button" id="rezz">
Result
<span id="counter">0</span>
</span>
<span class="button" id="ttime"></span>
<span class="button">
<a onclick="ResetGame();">Reset</a>
</span>
</span>
<div id="boxcard" align="center"></div>
</div>
This is JS Code that creates DIV blocks (i.e. Cards)
function ShuffleImages() {
var ImgAll = $(Source).children();
var ImgThis = $(Source + " div:first-child");
var ImgArr = new Array();
for (var i = 0; i < ImgAll.length; i++) {
ImgArr[i] = $("#" + ImgThis.attr("id") + " img").attr("src");
ImgThis = ImgThis.next();
}
ImgThis = $(Source + " div:first-child");
for (var z = 0; z < ImgAll.length; z++) {
var RandomNumber = RandomFunction(0, ImgArr.length - 1);
$("#" + ImgThis.attr("id") + " img").attr("src", ImgArr[RandomNumber]);
ImgArr.splice(RandomNumber, 1);
ImgThis = ImgThis.next();
}
}
$(function() {
for (var y = 1; y < 3 ; y++) {
$.each(ImgSource, function(i, val) {
$(Source).append("<div id=card" + y + i + "><img src=" + val + " />");
});
}
$(Source + " div").click(OpenCard);
ShuffleImages();
});
You need to add display: table. This is how you center an element with a undefined width
DEMO http://jsfiddle.net/s7w3q/2/
#boxcard {
z-index: 1;
display: table;
margin: 0px auto;
width: auto;
}
#boxcard div{
width: 100px;
display:inline-block;
height: 120px;
margin: 5px;
padding: 5px;
border: 4px solid #EE872A;
cursor: pointer;
border-radius: 10px;
box-shadow: 0 1px 5px rgba(0,0,0,.5);
background: #B1B1B1;
z-index: 2;
}
You were using float:left; on #boxcard div even when you were using align"center" withHTML`
Also you needed to use px after height and width
another way to do this would be more efficient. As it'd Remove the need to separately align boxbuttons.
#boxcard {
display: inline-block;
...
}
....
#picbox {
text-align: center;
...
}
Related
In my web application initially showing Image with overlapping the video when the user click on it the form will show up after submitting the form storing the value in cookie for One day. If cookie have value the YouTube video will show. So that user can watch this is the functionality we have.
The functionality are working but the video are not showing if cookies have value. For this I tried below code.
Here I have submitting the code If cookie have value replacing the YouTube video. It's not working for me. Please suggest us where I went wrong.
<html>
<head>
<title>Set Cookies</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<style type="text/css">
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: -60px;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #f7f7f7;
margin: auto;
padding: 20px;
border: 1px solid #888;
max-width: 340px;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal{
padding-left: 35px;
padding-right: 35px;
}
#contactform input,select {
height: 40px;
border: 1px solid #C6C6C6;
color: #000;
margin: 5px 0 0;
}
.errorMessage{
color: #d13800;
font-size: 12px;
display: none;
}
.customButton{
background-color: #0095eb !important;
color: #fff !important;
}
</style>
<style type="text/css">
.youTypeLink{
display: none;
}
.thumb {
display: flex;
flex-wrap: wrap;
list-style: none;
}
.thumb li {
width: 193px;
}
.thumb li ~ li {
margin-left: 20px;
}
.thumb .thumbCaption {
padding: 10px 0;
}
.overlay {
position: relative;
}
.overlay .thumbnail {
display: block;
}
.overlay .time {
position: absolute; z-index: 2;
right: 3px; bottom: 3px;
padding: 2px 5px;
background-color: rgba(0, 0, 0, 0.6);
color: white;
}
.overlay .playWrapper {
opacity: 0;
position: absolute; z-index: 1;
top: 0;
width: 192px; height: 109px;
background: rgba(0,0,0,0.6) url("http://wptf.com/wp-content/uploads/2014/05/play-button.png") no-repeat scroll center center / 50px 50px;
}
.playWrapper .playBtn {
position: absolute;
z-index: 2;
width: 50px;
height: 50px;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto; /* center */
}
.thumb .overlay:hover .playWrapper {
opacity: 1;
}
</style>
<script>
function setCookie(cname,cvalue,exdays) {
let d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
let user = getCookie("username");
if (user !== "") {
$('#youTubeImage').css({"display":"none !important"});
$('#youTypeLink').css({"display":"initial !important"});
/* player = new YT.Player('player', {
width : '320',
height : '180',
videoId : 'qlEUrEVqDbo',
playerVars: { 'autoplay': 1 },
events : {
'onReady' : onPlayerReady,
'onStateChange' : onPlayerStateChange
}
});*/
console.log(user);
setCookie("username", "cookiesValue", 1);
}else{
$('#youTubeImage').css({"display":"initial"});
$('#youTypeLink').css({"display":"none"});
}
</script>
</head>
<body>
<div>
<ul id="youTubeImage" class="thumb">
<li>
<div class="overlay">
<img class="thumbnail" src="https://homepages.cae.wisc.edu/~ece533/images/monarch.png" width="192" height="109" alt="">
<span class="time">3:28</span>
<a href="#" class="playWrapper" id="myBtn">
<!--<span class="playBtn"><img src="http://wptf.com/wp-content/uploads/2014/05/play-button.png" width="50" height="50" alt=""></span>-->
</a>
</div>
<div class="thumbCaption">This is the description of the video...</div>
</li>
</ul>
<div class="youTypeLink">
<ul class="thumb">
<li>
<div class="overlay">
<iframe width="370" height="303" src="https://www.youtube.com/embed/OXmIptsCsw0">
</iframe>
</div>
<div class="thumbCaption">This is the description of the video...</div>
</li>
</ul>
</div>
</div>
</body>
</html>
Please suggest us to work properly. If cookie have value show video or else showing image.
Similar to Range input thumb gets offset over time
I have a slider range which will be used to select a point. Each point on the slider corresponds to the value of that point. Min and Max attributes are overwritten by jQuery.
<div class="range">
<input id="form-range" type="range">
<ul class="range-labels">
<li class="range-label">0</li>
<li class="range-label">1</li>
<li class="range-label">2</li>
<li class="range-label">3</li>
</ul>
</div>
The issue is that each label is not matching to the slider-thumb (or is ever so slightly offset). I have used jQuery to calculate the width of the slider, and grab each child li of the .range-labels class, and then set the width of each child to the parent divided by the number of children (in this scenario, .range is 100% width and the input, and ul are full width to the parent).
Jquery
let range_input = $('#form-range'); // Get input element
let range_input_parent = range_input.parent(); // Get input element parent
let range_labels = $('.range-labels').children('li'); // Get each li inside of ul for labels
let range_width = range_input.width(); // Get width of input element
function calculateWidth() {
// Get width of input parent
let range_width_parent = range_input_parent.width();
// Calculate width percentage of each li based on Parent width
range_input_width_percent = range_width / range_width_parent * 100;
}
function setMinMaxAttr() {
// Create empty variable as min
let min = 0;
// Create max variable based on total number of li elements in range
let max = $('.range-label').length;
// Set input attributes max / min respectively
range_input.attr('max', max);
range_input.attr('min', min);
}
setMinMaxAttr();
calculateWidth();
// Set widths of li elements to percentage of parent width
function setElementWidth() {
let el = range_input_width_percent / range_labels.length;
// Set width as %
$(range_labels).css("width", el + "%");
}
setElementWidth();
CSS
.range {
position: relative;
width: 100%;
height: 5px;
padding-top: 40px;
}
.range input {
width: 100%;
position: absolute;
top: 2px;
height: 0;
-webkit-appearance: none;
}
.range input::-webkit-slider-thumb {
-webkit-appearance: none;
width: 18px;
height: 18px;
margin: -8px 0 0;
border-radius: 50%;
background: #37adbf;
cursor: pointer;
border: 0 !important;
}
.range input::-moz-range-thumb {
width: 18px;
height: 18px;
margin: 0 0 0;
border-radius: 50%;
background: #37adbf;
cursor: pointer;
border: 0 !important;
}
.range input::-ms-thumb {
width: 18px;
height: 18px;
margin: 0 0 0;
border-radius: 50%;
background: #37adbf;
cursor: pointer;
border: 0 !important;
}
.range input::-webkit-slider-runnable-track {
width: 100%;
height: 2px;
cursor: pointer;
background: #b2b2b2;
}
.range input::-moz-range-track {
width: 100%;
height: 2px;
cursor: pointer;
background: #b2b2b2;
}
.range input::-ms-track {
width: 100%;
height: 2px;
cursor: pointer;
background: #b2b2b2;
}
.range input:focus {
background: none;
outline: none;
}
.range input::-ms-track {
width: 100%;
cursor: pointer;
background: transparent;
border-color: transparent;
color: transparent;
}
.range-labels {
margin-top: 20px;
padding: 0;
list-style: none;
display: flex;
flex-direction: row;
}
.range-labels li {
position: relative;
text-align: left;
color: #b2b2b2;
font-size: 14px;
cursor: pointer;
}
JS Fiddle
https://jsfiddle.net/nbinks1/jg4169om/
I am making a site where you can click on a button and it will scroll you down to the information below. My issue is that the size of the opening screen is relative to the device screen. That means that a fixed scroll can be too far or not far enough on different devices. In summary my question is: how do i jump the exact device sreen height?
Here is my code:`
<div id='textPage1'>
<div id='leesMeer'>
<a href="#page2" class='leesMeer'type="button" value='Lees Meer'>LEES MEER</a>
</div>
</div>
<div id='page2'>
<div id='textPage2'>
<p>hi</p>
</div>
</div>
And my css:
#textPage1 {
float: right;
margin-right: 100px;
z-index: -1;
}
#beschrijving {
font-family: agency;
font-size: 20px;
color: #f2f2f2;
letter-spacing: 2px;
transform: scale(1, 1.1);
line-height: 30px;
z-index: 1;
margin-left: 50px;
}
.leesMeer {
font-family: agency;
font-size: 30px;
color: #f2f2f2;
border: 5px solid #f2f2f2;
border-radius: 15px;
padding: 12px 40px 12px 40px;
text-decoration: none;
-webkit-transition-duration: 0.5s;
position: absolute;
}
You can use Javascript to specify the scroll down like this example:
HTML:
<div class="first"><button type="button" onclick="smoothScroll(document.getElementById('second'))">Click Me!</button></div>
<div class="second" id="second">Hi</div>
CSS:
.first {
width: 100%;
height: 1000px;
background: #ccc;
}
.second {
width: 100%;
height: 1000px;
background: #999;
}
Javascript:
window.smoothScroll = function(target) {
var scrollContainer = target;
do { //find scroll container
scrollContainer = scrollContainer.parentNode;
if (!scrollContainer) return;
scrollContainer.scrollTop += 1;
} while (scrollContainer.scrollTop == 0);
var targetY = 0;
do { //find the top of target relatively to the container
if (target == scrollContainer) break;
targetY += target.offsetTop;
} while (target = target.offsetParent);
scroll = function(c, a, b, i) {
i++; if (i > 30) return;
c.scrollTop = a + (b - a) / 30 * i;
setTimeout(function(){ scroll(c, a, b, i); }, 20);
}
// start scrolling
scroll(scrollContainer, scrollContainer.scrollTop, targetY, 0);
}
here is the code in jsfiddle http://jsfiddle.net/rjSfP/
I am getting very annoyed because I cannot figure out where the problem with the styling is. My btnBox div keeps going outside of the noteBoxes div, I have messed around with it for more than an hour and still cannot solve the problem, don't worry about the js, sorry bout that. I just need help putting the btnBox div inside the noteBoxes div and to the right of the textarea. Any help is appreciated.
/* textarea styling for notes */
.notesE {
width: 478px;
max-width: 478px;
height: 100px;
margin: 0 auto;
margin-left: 0;
border: none;
padding: 5px;
overflow: hidden;
resize: none;
clear: both;
}
.btnBox {
height: 100px;
border: none;
width: 11px;
clear: both;
top: 0px;
}
/* remove note button */
.removeNote {
width: 10px;
height: 50px;
margin-left: 0;
margin-right: 0;
background-color: #fc7979;
border: none;
cursor: pointer;
margin-top: -4px;
margin-left: 0;
clear: both;
}
.saveNote {
width: 10px;
height: 50px;
margin-left: 0;
margin-right: 0;
background-color: #46e68b;
border: none;
cursor: pointer;
clear: both;
}
/* div that holds note and button and date */
.noteBoxes {
width: 510px;
height: 128px;
margin-bottom: 15px;
}
.dateTxt {
margin-bottom: 0;
margin-top: 0;
color: #ccc;
}
<div id="custNotes" style="width: 550px; margin: 0 auto;">
<h3>
<!-- Customer Value-->Notes</h3>
<button class="options" onclick="addNote()" style="margin-bottom: 10px;">add</button>
<p id="Message"></p>
<div class="notesScroll" style="width: 550px; background-color: #606060; margin: 0 auto;">
<div id="notesBox" style="padding: 10px; width: 510px;">
<!-- <div class="btnBox" style="width: 10px; height: 100px;">
<button class="saveNote"></button>
<button class="removeNote" style="margin-top: -4px; margin-left: 0;"></button>
</div> -->
</div>
</div>
</div>
You appear to have a default height set on noteboxes, so when the button box renders it renders beyond the default height. If you remove the default height the noteboxes will stretch to contain the buttonboxes. Is that what you are looking for?
var noteCount = 0;
function addNote(style) {
const notesBox = document.getElementById('notesBox');
var noteBoxes = document.createElement('div');
textarea = document.createElement('textarea'),
btnBox = document.createElement('div'),
save = document.createElement('button'),
remove = document.createElement('button'),
today = new Date();
var txtElement = document.createElement('p');
var dateString = '' + today.toLocaleDateString() + ' ' + today.getHours() + ':' + today.getMinutes();
txtElement.innerHTML = dateString;
txtElement.setAttribute('class', style);
txtElement.className = 'dateTxt';
txtElement.setAttribute('id', style);
txtElement.id = 'note ' + noteCount + ' date';
txtElement.setAttribute('data-month', today.getMonth() + 1);
txtElement.setAttribute('data-year', today.getFullYear());
// div that holds each note and remove button and date
notesBox.appendChild(noteBoxes);
noteBoxes.setAttribute('class', style);
noteBoxes.className = 'noteBoxes';
noteBoxes.setAttribute('id', style);
noteBoxes.id = 'note box ' + noteCount;
noteBoxes.appendChild(txtElement);
noteBoxes.appendChild(textarea);
noteBoxes.appendChild(btnBox);
// note that is added
textarea.setAttribute('class', style);
textarea.className = 'notesE';
textarea.setAttribute('id', style);
textarea.id = 'note' + noteCount;
// button box
btnBox.setAttribute('class', style);
btnBox.className = 'btnBox';
btnBox.setAttribute('id', style);
btnBox.id = 'btnBox' + noteCount;
btnBox.appendChild(save);
btnBox.appendChild(remove);
// save button
save.setAttribute('title', style);
save.title = 'save';
save.setAttribute('class', style);
save.className = 'saveNote';
save.setAttribute('id', style);
save.id = '+Note' + noteCount;
// button to remove note
remove.setAttribute('title', style);
remove.title = 'delete';
remove.setAttribute('class', style);
remove.className = 'removeNote';
remove.setAttribute('id', style);
remove.id = '-Note' + noteCount;
remove.onclick = function() {
// confirm alert dialog
// deletes the note if user selects 'OK'
if (confirm("Are you sure you want to delete this note?") == true) {
// removes the noteBoxes div of which the button clicked is in.
this.parentElement.remove();
}
}
noteCount++;
console.log(textarea.id);
var month = document.getElementById('selectMonth');
var year = document.getElementById('selectYear');
var searchDate = document.getElementById('searchDate');
}
/* textarea styling for notes */
.notesE {
width: 478px;
max-width: 478px;
height: 100px;
margin: 0 auto;
margin-left: 0;
border: none;
padding: 5px;
overflow: hidden;
resize: none;
clear: both;
}
.btnBox {
height: 100px;
border: none;
width: 11px;
clear: both;
top: 0px;
}
/* remove note button */
.removeNote {
width: 10px;
height: 50px;
margin-left: 0;
margin-right: 0;
background-color: #fc7979;
border: none;
cursor: pointer;
margin-top: -4px;
margin-left: 0;
clear: both;
}
.saveNote {
width: 10px;
height: 50px;
margin-left: 0;
margin-right: 0;
background-color: #46e68b;
border: none;
cursor: pointer;
clear: both;
}
/* div that holds note and button and date */
.noteBoxes {
width: 510px;
margin-bottom: 15px;
}
.dateTxt {
margin-bottom: 0;
margin-top: 0;
color: #ccc;
}
<div id="custNotes" style="width: 550px; margin: 0 auto;">
<h3>
<!-- Customer Value-->Notes</h3>
<button class="options" onclick="addNote()" style="margin-bottom: 10px;">add</button>
<p id="Message"></p>
<div class="notesScroll" style="width: 550px; background-color: #606060; margin: 0 auto;">
<div id="notesBox" style="padding: 10px; width: 510px;">
<!-- <div class="btnBox" style="width: 10px; height: 100px;">
<button class="saveNote"></button>
<button class="removeNote" style="margin-top: -4px; margin-left: 0;"></button>
</div> -->
</div>
</div>
</div>
If you want a text-area and those two buttons on the right side of the text-area. Check the following changes ->
/* textarea styling for notes */
.notesE {
width: 478px;
max-width: 478px;
height: 100px;
margin: 0 auto;
margin-left: 0;
border: none;
padding: 5px;
overflow: hidden;
resize: none;
clear: both;
}
.btnBox {
height: 100px;
border: none;
width: 11px;
clear: both;
top: 0px;
float:right;
}
/* remove note button */
.removeNote {
width: 10px;
height: 50px;
margin-left: 0;
margin-right: 0;
background-color: #fc7979;
border: none;
cursor: pointer;
margin-top: -4px;
margin-left: 0;
clear: both;
}
.saveNote {
width: 10px;
height: 50px;
margin-left: 0;
margin-right: 0;
background-color: #46e68b;
border: none;
cursor: pointer;
clear: both;
}
/* div that holds note and button and date */
.noteBoxes {
width: 510px;
height: 128px;
}
.dateTxt {
margin-bottom: 0;
margin-top: 0;
color: #ccc;
}
.notesScroll{
width: 510px;
background-color: #606060;
margin: 0 auto;
height: 100px;
}
}
<div id="custNotes" style="width: 550px; margin: 0 auto;">
<h3>
<!-- Customer Value-->Notes</h3>
<button class="options" onclick="addNote()" style="margin-bottom: 10px;">add</button>
<p id="Message"></p>
<div class="notesScroll" >
<div id="notesBox" class= noteBoxes>
<div class="btnBox" >
<button class="saveNote"></button>
<button class="removeNote" style="margin-top: -4px; margin-left: 0;"> </button>
</div>
</div>
</div>
</div>
I'm making a messaging app in Electron. I'm using backdrop-filter to blur the messages as they scroll past the title bar, so I need the messages to pass behind the title bar, rather than being contained inside their own div in the middle of the screen.
When the page is not scrolled, the messages behave as expected. However, at the bottom of the page, the messages are cut off by the bottom bar for entering messages.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Chat</title>
<link rel="stylesheet" href="css/chat.css" />
<script src="js/chatWindow.js"></script>
</head>
<body>
<div class="header">
<span class="name">Room Name</span>
</div>
<div class="messageBar">
<input id="messageBox" type="text" placeholder="Enter a message..." />
<div class="sendBtn">Send</div>
</div>
<div class="messageList"></div>
</body>
</html>
CSS
#font-face {
font-family: "Roboto Light";
font-style: "normal";
font-weight: 400;
src: url("fonts/Roboto-Light.ttf") format("truetype");
}
body {
background-color: white;
font-family: "Roboto Light";
padding: 45px 0px;
}
.header {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 45px;
z-index: 100;
background-color: rgba(56, 92, 254, 0.75);
display: flex;
text-align: center;
justify-content: center;
align-items: center;
backdrop-filter: blur(3px);
-webkit-backdrop-filter: blur(3px);
-webkit-app-region: drag;
}
.header span {
font-weight: bold;
}
.messageBar {
position: fixed;
top: calc(100% - 45px);
left: 0px;
width: 100%;
height: 45px;
z-index: 100;
background-color: rgba(57, 93, 255, 0.75);
padding: 0px;
display: flex;
text-align: center;
justify-content: center;
align-items: center;
vertical-align: middle;
backdrop-filter: blur(3px);
-webkit-backdrop-filter: blur(3px);
}
#messageBox {
width: 90%;
height: 100%;
background-color: rgba(255,255,255,0.5);
font-size: 1em;
margin: none;
border: none;
padding: 0px 5px 0px 5px;
}
#messageBox::-webkit-input-placeholder {
color: dimgray;
}
.sendBtn {
float: right;
width: 10%;
height: 100%;
padding: 0px 3px;
line-height: 45px;
transition: 0.2s;
}
.sendBtn:hover {
background-color: rgba(0,0,0,0.25);
}
.messageList {
width: 100%;
height: 100%;
padding: 0px;
margin: 0px;
}
.message {
display: block;
width: auto;
max-width: 50%;
border-radius: 10px;
padding: 4px;
margin: 5px 0px;
box-sizing: border-box;
background-color: lightblue;
overflow-wrap: break-word;
float: left;
clear: both;
}
.message.mine {
float: right;
background-color: lightgreen;
}
Does anybody know how to fix this issue? Here's a CodePen for an example of what's happening. Any help would be greatly appreciated!
Try this javascript code may this help you.
window.addEventListener("load", function(){
var messageList = document.querySelector(".messageList");
var messageBox = document.getElementById("messageBox")
var sendBtn = document.querySelector(".sendBtn");
for(var i = 0; i < 100; i++) {
var content = "Message body: " + i + "\nThe quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.";
createMessageBubble(content, Math.random() > 0.5);
}
sendBtn.onclick = function() {
var message = messageBox.value;
messageBox.value = "";
if(!message || message.length <= 0) {
return;
}
createMessageBubble(message, true);
// TODO: actually send the message
};
function createMessageBubble(content, isUser) {
var el = document.createElement("div");
el.classList.add("message");
if(isUser) {
el.classList.add("mine");
}
el.innerText = content;
messageList.appendChild(el);
}
var div = document.createElement("div");
div.style.width = "100%";
div.style.height = "45px";
div.style.float = "left";
messageList.parentNode.appendChild(div);
});