這篇文章給大家分享的是有關(guān)js如何仿微博實現(xiàn)動態(tài)欄功能的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比淮安區(qū)網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式淮安區(qū)網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋淮安區(qū)地區(qū)。費用合理售后完善,十載實體公司更值得信賴。
效果圖:

代碼如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>微博</title>
<style>
body, p, img, ul, li { margin: 0; padding: 0; }
body { background-image: url("http://cdn.attach.qdfuns.com/notes/pics/201612/07/212742f92tpe2wve095ttp.jpg");}
li { list-style: none; }
.box {
padding-top: 20px;
margin: 20px auto;
width: 620px;
height: 180px;
position: relative;
background-color: #ffffff;
text-align: center;
}
.box label {
font: 18px/18px "微軟雅黑";
color: #cccccc;
position: absolute;
top: 60px;
left: 40px;
cursor: text;
}
.H {
float: left;
padding: 5px 0 5px 10px;
color: #426B80;
font: 400 16px/16px "宋體";
}
textarea {
padding: 5px;
border-color: #CCCCCC;
width: 580px;
height: 80px;
resize: none;
outline:none;
font: 400 18px "微軟雅黑";
color: #333333;
}
#button {
width: 80px;
height: 34px;
display: block;
background-color: #FFC09F;
position: absolute;
top: 148px;
right: 14px;
text-align: center;
line-height: 34px;
color: #ffffff;
cursor: pointer;
/*F7671D*/
}
.dynamic {
text-align: left;
padding: 10px 10px;
width: 580px;
height: 100%;
}
.user {
position: relative;
}
.user img {
border: solid 1px #CCCCCC;
vertical-align: top;
}
.user .name {
display: block;
position: absolute;
top: 8px;
left: 60px;
font: 600 18px/18px "微軟雅黑";
}
.time{
display: block;
position: absolute;
top: 55px;
left: 80px;
font: 500 10px/10px "微軟雅黑";
}
.dynamic .user {
margin: 10px 5px 0 10px;
}
.dynamic .list {
font: 500 16px/16px "微軟雅黑";
padding-left: 70px;
}
</style>
<script>
window.onload = function () {
//獲取當前時間函數(shù)
function time() {
var maydate = new Date();
var Time = maydate.getFullYear() + "-" + (maydate.getMonth()+1) +"-"+maydate.getDate()+" "+maydate.getHours()+":"+maydate.getMinutes();
return Time;
}
//獲取ID函數(shù)
function $(id) {return document.getElementById(id);}
//創(chuàng)建節(jié)點函數(shù)
function nweChild(id,text) {
//獲得節(jié)點ID
var parent = $(id);
//獲得body所有的孩子
var child = parent.parentNode.children;
//克隆當前節(jié)點和其所有子節(jié)點
var newNode = parent.cloneNode(true);
//給當前節(jié)點的父節(jié)點插入克隆的節(jié)點
parent.parentNode.insertBefore(newNode,child[1]);
//插入的克隆節(jié)點更換ID
child[1].id = id + (child.length - 2);
//改變時間
//獲取當前id節(jié)點的所有孩子
var idChild = child[1].children;
idChild[0].innerHTML = time();
idChild[2].innerHTML = $("text").value;
}
//獲得焦點改變邊框顏色和恢復(fù)默認字體顏色
$("text").onfocus = function () {
this.style.borderColor = "#FA7D3C";
this.style.color = "#333333";
}
//失去焦點恢復(fù)默然邊框顏色,改變字體顏色
$("text").onblur = function () {
this.style.borderColor = "#CCCCCC";
this.style.color = "#CCCCCC";
}
//監(jiān)聽輸入事件
$("text").oninput = function () {
if($("text").value != ""){
//隱藏提示文本
$("txt").style.display = "none";
//文本域不為空 按鈕可點擊
$("button").style.backgroundColor = "#FF8140";
}else{
//顯示提示文本
$("txt").style.display = "block";
//文本域為空 按鈕不可點擊
$("button").style.backgroundColor = "#FFC09F";
}
}
//按鈕事件
$("button").onmousemove = function () {
//當文本域不為空執(zhí)行下面按鈕事件
if($("text").value != ""){
$("button").onmouseout= function () {
//如果不為空 按鈕為亮色
if($("text").value != ""){
this.style.backgroundColor = "#FF8140";
}else {
//恢復(fù)按鈕為不可點擊顏色
$("button").style.backgroundColor = "#FFC09F";
}
}
//按鈕為高亮
this.style.backgroundColor = "#F7671D";
//調(diào)用節(jié)點函數(shù),并把傳遞當前文本內(nèi)容
$("button").onclick = function () {
if($("text").value != ""){
nweChild("order",$("text").value);
}
//清空當前文本
$("text").value = "";
//恢復(fù)按鈕為不可點擊顏色
$("button").style.backgroundColor = "#FFC09F";
//更改提示文本內(nèi)容
$("txt").innerHTML = "你看,沒騙你吧!"
//顯示提示文本
$("txt").style.display = "block";
}
}
}
}
</script>
</head>
<body>
<div class="box">
<span class="H">有什么新鮮事想告訴大家?</span>
<textarea name="text" id="text"></textarea>
<label for="text" id="txt">輸入一段話,點發(fā)布會有驚喜哦!</label>
<span id="button">發(fā)布</span>
</div>
<div class="box dynamic" id="order">
<span class="time">2016-12-07 21:20</span>
<div class="user">
<img src="http://cdn.attach.qdfuns.com/notes/pics/201612/07/212742m96ugh87fzxhuuxp.jpg" width=50; alt="頭像">
<span class="name">漫步未來</span>
</div>
<ul class="list">
<li>未來的你,一定會感謝現(xiàn)在拼命的自己。</li>
</ul>
</div>
</body>
</html>感謝各位的閱讀!關(guān)于“js如何仿微博實現(xiàn)動態(tài)欄功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
文章題目:js如何仿微博實現(xiàn)動態(tài)欄功能
新聞來源:http://chinadenli.net/article42/iijohc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、品牌網(wǎng)站制作、自適應(yīng)網(wǎng)站、網(wǎng)站策劃、軟件開發(fā)、虛擬主機
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)