最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js控住DOM實(shí)現(xiàn)發(fā)布微博效果

 更新時(shí)間:2016年08月30日 08:39:23   作者:騎豬敲代碼  
這篇文章主要為大家詳細(xì)介紹了js控住DOM實(shí)現(xiàn)發(fā)布微博效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

這段代碼的效果具體是輸入標(biāo)題和內(nèi)容,點(diǎn)擊發(fā)布把消息發(fā)布出去,并使最新的消息始終在內(nèi)容的最上面,代碼為:

<!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'>標(biāo)題:</span>
   <input id="title" type="text">
   <span class="span2">內(nèi)容:</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">發(fā)送</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('親~標(biāo)題或內(nèi)容不能為空');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]);//不可以,不知道綁定的是第幾個(gè)。
     }
    }
   }
  text.onfocus=function(){
   // console.log(prompt.children[0].innerHTML);//children是指帶有標(biāo)簽的子節(jié)點(diǎn);
   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';//為什么不變紅呢?因?yàn)檫@他妹的也是一個(gè)未來事件!
     // 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>

這段代碼主要運(yùn)用了一些DOM節(jié)點(diǎn)操作的知識(shí),純屬學(xué)習(xí)之余練手作品,大家可以參考參考。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • javascript json字符串到j(luò)son對(duì)象轉(zhuǎn)義問題

    javascript json字符串到j(luò)son對(duì)象轉(zhuǎn)義問題

    今天小編就為大家分享一篇關(guān)于javascript json字符串到j(luò)son對(duì)象轉(zhuǎn)義問題,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • Javascript生成器(Generator)的介紹與使用

    Javascript生成器(Generator)的介紹與使用

    這篇文章主要給大家介紹了關(guān)于Javascript生成器(Generator)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • 基于js?+?html2canvas實(shí)現(xiàn)網(wǎng)頁放大鏡功能

    基于js?+?html2canvas實(shí)現(xiàn)網(wǎng)頁放大鏡功能

    最近接到任務(wù),需實(shí)現(xiàn)【網(wǎng)頁】放大鏡的效果,百度搜索?【js?放大鏡】關(guān)鍵字,千篇一律的都是一些仿淘寶/京東等電商網(wǎng)站中查看規(guī)格大圖的效果實(shí)現(xiàn),根本無法滿足我的需求,于是自己花了點(diǎn)時(shí)間調(diào)研實(shí)現(xiàn),在這里分享給大家,感興趣的朋友可以參考下
    2023-12-12
  • uniapp如何實(shí)現(xiàn)tabBar之間傳參

    uniapp如何實(shí)現(xiàn)tabBar之間傳參

    這篇文章主要給大家介紹了關(guān)于uniapp如何實(shí)現(xiàn)tabBar之間傳參的相關(guān)資料,文中通過代碼示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-08-08
  • 創(chuàng)建基于Bootstrap的下拉菜單的DropDownList的JQuery插件

    創(chuàng)建基于Bootstrap的下拉菜單的DropDownList的JQuery插件

    這篇文章主要介紹了創(chuàng)建基于Bootstrap的下拉菜單的DropDownList的JQuery插件 的相關(guān)資料,需要的朋友可以參考下
    2016-06-06
  • 如何用JS獲取帶“\”字符串的中間值?

    如何用JS獲取帶“\”字符串的中間值?

    如何用JS獲取帶“\”字符串的中間值?...
    2007-02-02
  • 小程序?qū)崿F(xiàn)滑動(dòng)塊效果

    小程序?qū)崿F(xiàn)滑動(dòng)塊效果

    這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)滑動(dòng)塊,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • JS實(shí)現(xiàn)漂亮的淡藍(lán)色滑動(dòng)門效果代碼

    JS實(shí)現(xiàn)漂亮的淡藍(lán)色滑動(dòng)門效果代碼

    這篇文章主要介紹了JS實(shí)現(xiàn)漂亮的淡藍(lán)色滑動(dòng)門效果代碼,涉及JavaScript通過自定義函數(shù)遍歷頁面元素及動(dòng)態(tài)設(shè)置元素屬性的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • 淺談js中startsWith 函數(shù)不能在任何瀏覽器兼容的問題

    淺談js中startsWith 函數(shù)不能在任何瀏覽器兼容的問題

    下面小編就為大家?guī)硪黄獪\談js中startsWith 函數(shù)不能在任何瀏覽器兼容的問題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-03-03
  • javascript實(shí)現(xiàn)下雪效果【實(shí)例代碼】

    javascript實(shí)現(xiàn)下雪效果【實(shí)例代碼】

    下面小編就為大家?guī)硪黄猨avascript實(shí)現(xiàn)下雪效果【實(shí)例代碼】。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考
    2016-05-05

最新評(píng)論

丰原市| 灵川县| 阳曲县| 莎车县| 福贡县| 松溪县| 阳谷县| 谢通门县| 丰顺县| 栾川县| 二连浩特市| 勃利县| 白银市| 乌鲁木齐市| 和平区| 手机| 高邑县| 九龙城区| 当涂县| 东阿县| 古田县| 财经| 平遥县| 改则县| 冷水江市| 渑池县| 崇义县| 松桃| 茶陵县| 安图县| 易门县| 巴林左旗| 八宿县| 宜宾市| 封开县| 万年县| 蒲江县| 黄山市| 安福县| 吉隆县| 衡水市|