js仿微博動態(tài)欄功能
知識有限,目前只寫了發(fā)布動態(tài)的功能,沒有寫兼容,后面再慢慢完善。嘿嘿
效果圖:

代碼如下:
<!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 () {
//獲取當(dāng)前時(shí)間函數(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é)點(diǎn)函數(shù)
function nweChild(id,text) {
//獲得節(jié)點(diǎn)ID
var parent = $(id);
//獲得body所有的孩子
var child = parent.parentNode.children;
//克隆當(dāng)前節(jié)點(diǎn)和其所有子節(jié)點(diǎn)
var newNode = parent.cloneNode(true);
//給當(dāng)前節(jié)點(diǎn)的父節(jié)點(diǎn)插入克隆的節(jié)點(diǎn)
parent.parentNode.insertBefore(newNode,child[1]);
//插入的克隆節(jié)點(diǎn)更換ID
child[1].id = id + (child.length - 2);
//改變時(shí)間
//獲取當(dāng)前id節(jié)點(diǎn)的所有孩子
var idChild = child[1].children;
idChild[0].innerHTML = time();
idChild[2].innerHTML = $("text").value;
}
//獲得焦點(diǎn)改變邊框顏色和恢復(fù)默認(rèn)字體顏色
$("text").onfocus = function () {
this.style.borderColor = "#FA7D3C";
this.style.color = "#333333";
}
//失去焦點(diǎn)恢復(fù)默然邊框顏色,改變字體顏色
$("text").onblur = function () {
this.style.borderColor = "#CCCCCC";
this.style.color = "#CCCCCC";
}
//監(jiān)聽輸入事件
$("text").oninput = function () {
if($("text").value != ""){
//隱藏提示文本
$("txt").style.display = "none";
//文本域不為空 按鈕可點(diǎn)擊
$("button").style.backgroundColor = "#FF8140";
}else{
//顯示提示文本
$("txt").style.display = "block";
//文本域?yàn)榭?按鈕不可點(diǎn)擊
$("button").style.backgroundColor = "#FFC09F";
}
}
//按鈕事件
$("button").onmousemove = function () {
//當(dāng)文本域不為空執(zhí)行下面按鈕事件
if($("text").value != ""){
$("button").onmouseout= function () {
//如果不為空 按鈕為亮色
if($("text").value != ""){
this.style.backgroundColor = "#FF8140";
}else {
//恢復(fù)按鈕為不可點(diǎn)擊顏色
$("button").style.backgroundColor = "#FFC09F";
}
}
//按鈕為高亮
this.style.backgroundColor = "#F7671D";
//調(diào)用節(jié)點(diǎn)函數(shù),并把傳遞當(dāng)前文本內(nèi)容
$("button").onclick = function () {
if($("text").value != ""){
nweChild("order",$("text").value);
}
//清空當(dāng)前文本
$("text").value = "";
//恢復(fù)按鈕為不可點(diǎn)擊顏色
$("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">輸入一段話,點(diǎn)發(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>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
響應(yīng)式框架Bootstrap柵格系統(tǒng)的實(shí)例
下面小編就為大家分享一篇響應(yīng)式框架Bootstrap柵格系統(tǒng)的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12
JavaScript實(shí)現(xiàn)簡易計(jì)算器功能的兩種方法
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡易計(jì)算器功能的兩種方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
js操作輸入框提示信息且響應(yīng)鼠標(biāo)事件
注冊網(wǎng)站的輸入框就有默認(rèn)提示值,當(dāng)獲取鼠標(biāo)焦點(diǎn)的時(shí)候,默認(rèn)值被刪除,當(dāng)用戶沒輸入東西焦點(diǎn)離開的時(shí)候,又恢復(fù)默認(rèn)提示值2014-03-03
JS實(shí)現(xiàn)仿FLASH效果的豎排導(dǎo)航代碼
這篇文章主要介紹了JS實(shí)現(xiàn)仿FLASH效果的豎排導(dǎo)航代碼,涉及JavaScript基于定時(shí)函數(shù)動態(tài)設(shè)置頁面元素樣式的技巧,具有FLASH變換效果,需要的朋友可以參考下2015-09-09
解讀Bootstrap v4 sass設(shè)計(jì)
這篇文章主要介紹了Bootstrap v4 sass設(shè)計(jì)的相關(guān)資料,需要的朋友可以參考下2016-05-05
bootstrap如何讓dropdown menu按鈕式下拉框長度一致
bootstrap框架提供了下拉菜單組件(dropdown),即點(diǎn)擊一個(gè)元素或按鈕,觸發(fā)隱藏的列表顯示出來。下面通過本文給大家介紹bootstrap如何讓dropdown menu按鈕式下拉框長度一致,需要的朋友可以參考下2017-04-04
CocosCreator骨骼動畫之龍骨DragonBones
這篇文章主要介紹了怎么在CocosCreator中使用骨骼動畫龍骨DragonBones,對骨骼動畫感興趣的同學(xué),可以試一下2021-04-04

