js仿新浪微博消息發(fā)布功能
更新時間:2017年02月17日 16:30:03 作者:jingtian678
這篇文章主要為大家詳細介紹了js仿新浪微博消息發(fā)布功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js仿新浪微博消息發(fā)布的具體代碼,供大家參考,具體內容如下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>仿新浪微博消息發(fā)布功能</title>
<style>
*{margin: 0; padding: 0;}
#div1{width: 400px; height: 400px; border: 1px solid; margin:10px auto; position: relative;overflow: hidden;}
#ul1 li{border-bottom: 1px #999 dashed; padding: 4px; list-style: none;filter: alpha(opacity:0);
opacity: 0;}
</style>
<script src="js/chuan.js"></script>
</head>
<body>
<textarea rows="5" cols="30" id="txt1"value=""></textarea>
<input type="button" id="btn1" value="發(fā)布" />
<div id="div1">
<ul id="ul1"></ul>
</div>
<script>
var oUl=document.getElementById('ul1');
var oTxt1=document.getElementById('txt1');
var oBtn=document.getElementById('btn1');
oBtn.onclick=function()
{
var oLi=document.createElement('li');
oLi.innerHTML=oTxt1.value;
oTxt1.value='';
if(oUl.children.length>0)
{
oUl.insertBefore(oLi,oUl.children[0]);
}
else
{
oUl.appendChild(oLi);
}
var iHeight=oLi.offsetHeight;
oLi.style.height=0;
move(oLi,{height:iHeight},function()
{
move(oLi,{opacity:100});
});
}
</script>
</body>
</html>
chuan,js為之前寫的完美運動框架:
function getstyle(obj,name)
{
if(obj.currentStyle)
{
return obj.currentStyle;
}
else
{
return getComputedStyle(obj,false)[name];
}
}
function move(obj,json,fnEnd)
{
clearInterval(obj.timer);
obj.timer=setInterval(function()
{
var bBox=true;//假設所有值都已經(jīng)到了
for(var strr in json)
{
if(strr=='opacity')
{
var cur=Math.round(parseFloat(getstyle(obj,strr))*100);
}
else
{
var cur=parseInt(getstyle(obj,strr));
}
var speed=(json[strr]-cur)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur!=json[strr])
bBox=false;
if(strr=='opacity')
{
obj.style.filter='alpha(opacity:'+(cur+speed+')');
obj.style.opacity=(cur+speed)/100;
}
else
{
obj.style[strr]=cur+speed+'px';
}
}
if(bBox)
{
clearInterval(obj.timer);
if(fnEnd)fnEnd();
}
},30);
};
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- JS實現(xiàn)模仿微博發(fā)布效果實例代碼
- PHP+Mysql+jQuery實現(xiàn)發(fā)布微博程序 jQuery篇
- 基于jquery DOM寫的類似微博發(fā)布的效果
- JS實現(xiàn)仿新浪微博發(fā)布內容為空時提示功能代碼
- 使用新浪微博API的OAuth認證發(fā)布微博實例
- PHP+Mysql+jQuery實現(xiàn)發(fā)布微博程序 php篇
- JavaScript制作頁面倒計時器的實現(xiàn)
- 基于javascript制作微博發(fā)布欄效果
- 基于jQuery實現(xiàn)仿微博發(fā)布框字數(shù)提示
- JavaScript仿微博發(fā)布信息案例
相關文章
封裝運動框架實戰(zhàn)左右與上下滑動的焦點輪播圖(實例)
下面小編就為大家?guī)硪黄庋b運動框架實戰(zhàn)左右與上下滑動的焦點輪播圖(實例)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10
JavaScript使用pop方法移除數(shù)組最后一個元素用法實例
這篇文章主要介紹了JavaScript使用pop方法移除數(shù)組最后一個元素,實例分析了javascript中pop方法的使用技巧,需要的朋友可以參考下2015-04-04
Javascript ES6中對象類型Sets的介紹與使用詳解
這篇文章主要給大家介紹了關于Javascript ES6中Sets的介紹與使用的相關資料,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面跟著小編來一起學習學習吧。2017-07-07

