I have created a little javascript snippet that can take two inputs and make a sort of "post" using those. In those posts, it says something like:
Hi!
Posted by Random Person _ minutes ago.
but without the underscore, it should say the lapsed time between now and the time posted. I am having difficulty thinking of how to do this, but this is what I am currently using:
$('#b').click(function () {
var v = $('#type').val();
var u = $('#input').val();
if (v !== "" && u !== "") {
var time = new Date();
var currentime = Date.now();
var x = currentime - time;
$("ul").prepend("<li>" + v + "<br />Posted by " + u + " " + x + " minutes ago </li>");
$('#type, #input').css('border', '');
} else if (v == "" && u == "") {
$('#type, #input').css('border', '1px solid red');
} else if (v == "") {
$('#type').css('border', '1px solid red');
$('#input').css('border', '');
} else {
$('#input').css('border', '1px solid red');
$('#type').css('border', '');
}
});
#type, #input {
border-radius: 10px;
background: #dadae3;
color: #59ACFF;
border: 1px solid #dadae3;
}
#type {
border-bottom-right-radius: 0;
}
#type:hover, #input:hover {
background: #c4c4cc;
color: #488CCF;
border: 1px solid #c4c4cc;
}
#type:hover::-webkit-input-placeholder {
color: #59ACFF
}
#input:hover::-webkit-input-placeholder {
color: #59ACFF
}
#type:focus, #input:focus {
border: 1px solid #59ACFF;
outline: 0;
}
button {
height: 30px;
background: #dadae3;
border-radius: 10px;
border: 1px solid #dadae3;
color: #59ACFF;
cursor: pointer;
}
button:hover {
background: #c4c4cc;
color: #488CCF;
border: 1px solid #c4c4cc;
}
button:focus {
outline: 0;
}
<script src="http://ift.tt/Zv5K7g"></script>
<link href="http://ift.tt/1FHelXo" rel="stylesheet"/>
<link href="http://ift.tt/18QXBAt" rel="stylesheet"/>
<br />
<textarea id='type'></textarea>
<br />
<br />
<input id='input'>
<br />
<br />
<button id='b'><span class='fa fa-plus-square-o fa-2x'></span>
</button>
<ul id='ul'></ul>
I realize that this is wrong, but I cannot think of other ways to do this.
Thank you. :)
Aucun commentaire:
Enregistrer un commentaire