The effect of a Twitter-like tweet written by Dom in JavaScript

Source: Internet
Author: User
Tags min set time
The code is as follows Copy Code
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title> Micro Blog Release </title>
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "" >
<style type= "Text/css" >
h1{margin:20px Auto;font-size:30px;width:200px;text-align:center;color:blue;}
#test1 {display:block;width:400px;height:70px;margin:20px auto 10px;}
#test2 {display:block;margin-left:800px;width:60px;height:30px;font-size:20px;}
#test3 {margin:10px auto;border:1px #444 Solid;width:400px;min-height:300px;padding-bottom:10px;overflow:hidden; Color:blue;}
. test{border:1px Blue Solid;width:400px;overflow:hidden;
. Time{margin-left:240px;color: #666; font-size:16px;}
. inf{margin:10px 10px;}
. con{margin:10px;min-height:20px;}
</style>
<body>
<input type= "text" id= "test1" value= ""/>
<input type= "button" id= "Test2" value= "Publish"/>
<div id= "Test3" ></div>
<script type= "Text/javascript" >
<!--
var Test1=document.getelementbyid ("Test1");
var Test2=document.getelementbyid ("Test2");
var Test3=document.getelementbyid ("Test3");
var t,r,i=0;

Click the Publish method
Test2.onclick=move;
function Move () {
var test=document.createelement (' div '); Create a micro-blog box node
if (test1.value== "") {//If the input is blank, re-enter
Alert ("Pro, please input content Oh!") ");
Return
}else{
Test.setattribute ("Class", "test"); CSS style for test
test.innerhtml = ' <p class= ' con ' > ' +test1.value+ ' </p> '; Adding content to a node
Test3.insertbefore (Test,test3.firstchild); Insert the created node into the Temp3 document, and the latest release is placed in the first
Test1.value= ""; When the tweet is posted, the contents of the input box disappear.
Micro-Blog Frame movement
var Child=document.getelementbyid ("Test3"). ChildNodes; Get all child nodes of all TEST3
var n=-test.offsetheight;
function run () {//click button, micro-blog Frame movement method
n++;
test.style.margintop=n+ "px";
if (n>=0) {n=0;return;cleartimeout (t);} Here return?????
T=settimeout (run,20);
}run ();
}
Create a micro-blog time and delete button node
var inf=document.createelement (' div '); Create a div node, the purpose of which is to include time and delete button events
Inf.setattribute ("Class", "INF"); The CSS style of the INF
var d=new Date (); Set time
inf.innerhtml = ' <span class= ' time ' > ' +d.gethours () + "when" +d.getminutes () + "Min" +d.getseconds () + "SEC" + ' </span> ';//binding time between
Test.appendchild (INF); Insert the INF node into test
var del=document.createelement (' input '); Create Delete button node
Del.type= "button"; Type of input is button
del.value= "Delete";
Del.style.float= "Right";
Inf.appendchild (DEL); The DEL node is inserted into test
Delete a button event, delete the animation effect
Del.onclick=dele;
function dele () {
Click on the button and the microblog disappears
var m=test.offsetheight; The value of the height cannot be assigned directly to the variable, so there is no test.style.height here
function run2 () {
m--;
R=settimeout (run2,20);
test.style.height=m+ "px";
if (m<=0)
{m=0;cleartimeout (R); Test3.removechild (test);} Test3.removechild (test)//delete the contents of test
}run2 ();
}
}
-->
</script>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.