English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
本文实例为大家分享了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="btn">1" value="발행" /> <div id="div">1"> <ul id="ul">1></ul> </div> <script> var oUl=document.getElementById('ul');1); var oTxt1=document.getElementById('txt');1); var oBtn=document.getElementById('btn');1); 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>
추간, 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); };
이것이 이 문서의 전체 내용입니다. 많은 도움이 되길 바랍니다. 또한, 외취教程에 많은 지지를 부탁드립니다.
선언: 이 문서의 내용은 인터넷에서 가져왔으며, 저작권자의 소유물입니다. 내용은 인터넷 사용자가 자발적으로 기여하고 업로드한 것이며, 이 사이트는 소유권을 가지지 않으며, 인공적인 편집을하지 않았으며, 관련 법적 책임도 부담하지 않습니다. 저작권 문제가 의심되는 내용이 있으면, notice#w로 이메일을 보내 주세요.3codebox.com(보내는 이메일에서 #을 @으로 변경하십시오. 신고하시고 관련 증거를 제공하시면, 사실이 확인되면, 이 사이트는 즉시 의심스러운 저작권 내용을 삭제합니다。)