js仿新浪微博消息发布功能
程序员文章站
2023-11-17 13:06:10
本文实例为大家分享了js仿新浪微博消息发布的具体代码,供大家参考,具体内容如下
<...
本文实例为大家分享了js仿新浪微博消息发布的具体代码,供大家参考,具体内容如下
<!doctype html> <html> <head> <meta charset="utf-8"> <title>仿新浪微博消息发布功能</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="发布" /> <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;//假设所有值都已经到了 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); };
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。