这段代码的效果具体是输入标题和内容,点击发布把消息发布出去,并使最新的消息始终在内容的最上面,代码为:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>微博消息效果</title>
<style>
*{margin:0;padding: 0;}
.warp{
width: 600px;
margin:50px auto 0;
background-color: #ccc;
}
#box{
width: 600px;
height: 340px;
/*background-color: #ccc;*/
position: relative;
/*overflow: hidden;*/
/*margin:50px auto 0;*/
font-family: '微软雅黑';
}
#box .span1{
position: absolute;
font-size: 16px;
line-height: 16px;
top: 10px;
left: 5px;
}
#box .span2{
position: absolute;
font-size: 16px;
line-height: 16px;
top: 50px;
left: 5px;
}
#title{
position: absolute;
width: 460px;
height: 20px;
line-height: 20px;
font-size: 16px;
text-indent: 5px;
left: 70px;
top: 6px;
}
#text{
position: absolute;
width: 460px;
height: 250px;
resize: none;
top: 50px;
left: 70px;
text-indent: 5px;
font-size: 16px;
}
#box #prompt{
position: absolute;
top: 312px;
left: 340px;
}
#prompt1{
position: absolute;
top: 312px;
left: 340px;
display: none;
}
#send{
position: absolute;
height: 25px;
width: 60px;
line-height: 20px;
font-size: 16px;
top: 310px;
right: 68px;
}
#news{
list-style: none;
width: 490px;
margin:10px auto 0px;
padding-bottom: 5px;
}
#news li{
width: 490px;
font-size: 14px;
overflow: hidden;
background-color: #fff;
margin-bottom: 5px;
position: relative;
}
#news li h1{
font-size: 16px;
line-height: 20px;
}
#news li p{
text-indent: 5px;
clear: left;
}
#news li span{
position: absolute;
top: 0px;
right: 0px;
cursor: pointer;
}
#news span:hover{
color: red;
}
</style>
</head>
<body>
<div class="warp">
<div id="box">
<span class='span1'>标题:</span>
<input id="title" type="text">
<span class="span2">内容:</span>
<textarea id="text"></textarea>
<em id="prompt">还可以输入<var id="textnum">200</var>字</em>
<em id="prompt1">你已超出<var id="textnum1"></var>字</em>
<button id="send">发送</button>
</div>
<ul id="news">
<li><h1></h1><span></span>
<p></p>
</li>
</ul>
</div>
<script>
var title=document.getElementById('title');
var text=document.getElementById('text');
var send=document.getElementById('send');
var ul=document.getElementById('news');
var lis=ul.getElementsByTagName('li');
var prompt=document.getElementById('prompt');
var prompt1=document.getElementById('prompt1');
var textnum=document.getElementById('textnum');
var textnum1=document.getElementById('textnum1');
var timer1=null,timer2=null;
send.onclick=function(){
if (text.value==''||title.value=='') {
alert('亲~标题或内容不能为空');return false;
}
lis[0].innerHTML='<h1>'+title.value+'</h1><span>×</span><p>'+text.value+'</p>';
lis[0].children[1].setAttribute('id','close');
var newLi=document.createElement('li');
ul.insertBefore(newLi,lis[0]);
maxheight=lis[1].clientHeight;
lis[1].style.height=0+'px';
var x=0;
var minstep=0;
var maxstep=20;
var change=maxheight/maxstep;
clearInterval(timer1);
timer1=setInterval(function(){
minstep++;
if (minstep>=maxstep) {
clearInterval(timer1);
}
x+=change;
lis[1].style.height=x+'px';
},10)
title.value='';
text.value='';
var close=document.getElementById('close');
for (var i = 0; i < lis.length; i++) {
close.onclick=function(){
var isme=this.parentNode;
var x=this.parentNode.clientHeight;
var minstep=0;
var maxstep=20;
var change=x/maxstep;
clearInterval(timer1);
timer1=setInterval(function(){
minstep++;
if (minstep>=maxstep) {
clearInterval(timer1);
ul.removeChild(isme);
}
x-=change;
isme.style.height=x+'px';
},10)
// ul.removeChild(lis[i]);//不可以,不知道绑定的是第几个。
}
}
}
text.onfocus=function(){
// console.log(prompt.children[0].innerHTML);//children是指带有标签的子节点;
timer2=setInterval(function(){
if(text.value.length<190){
var num=200-text.value.length;
textnum.style.color='black';
// prompt.style.color='black';
textnum.innerHTML=num;//
// prompt.innerHTML='还可以输入<var id="textnum">'+num+'</var>字</em>';
}
if (text.value.length>=190&&text.value.length<=200){
var num=200-text.value.length;
// prompt.style.color='black';
textnum.style.color='red';//为什么不变红呢?因为这他妹的也是一个未来事件!
// prompt.innerHTML='还可以输入<var id="textnum">'+num+'</var>字</em>';
textnum.innerHTML=num;
}
if (text.value.length>200){
var num=text.value.length-200;
// prompt.style.color='red';
prompt.style.display='none';
prompt1.style.display='block';
textnum1.style.color='red';
textnum1.innerHTML=num;
}
// console.log(text.value.length);
},50)
}
text.onblur=function(){
clearInterval(timer2);
}
</script>
</body>
</html>
这段代码主要运用了一些DOM节点操作的知识,纯属学习之余练手作品,大家可以参考参考。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
js发布微博,js微博消息
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“js控住DOM实现发布微博效果”评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2025年10月28日
2025年10月28日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]