js仿微博動態(tài)欄功能
更新時間:2017年02月22日 11:04:00 作者:漫步未來
本文主要介紹了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 () {
//獲取當前時間函數(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>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
kindeditor編輯器點中圖片滾動條往上頂?shù)腷ug
這篇文章主要介紹了kindeditor編輯器點中圖片滾動條往上頂?shù)腷ug的相關(guān)資料,需要的朋友可以參考下2015-07-07
Javascript 原型和繼承(Prototypes and Inheritance)
前面我們看到了如何使用 constructor 來初始化對象。如果這樣做,那么每一個創(chuàng)建的新對象都會對那些相同的屬性,方法建立一個獨立的副本。而實際上有更加有效的方法來指定方法,常量,以及其他一些可被所有該類的對象共享的屬性。2009-04-04
js print打印網(wǎng)頁指定區(qū)域內(nèi)容的簡單實例
下面小編就為大家?guī)硪黄猨s print打印網(wǎng)頁指定區(qū)域內(nèi)容的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11

