又一枚精彩的彈幕效果jQuery實現

來源:互聯網
上載者:User

標籤:nbsp   button   url   center   ges   image   desc   簡易   microsoft   

精彩的彈幕效果分享給大家,具有一定的參考價值,感興趣的朋友可以嘗試製作彈幕,具體內容如下 

簡易彈幕效果:將發布的內容隨機顯示在彈幕右側,逐漸左移最後消失。


 

涉及知識點:val()、random()、height()、css()、append()、remove()等,主要是元素的操作

html代碼:

?
123456789 <a href="#">彈幕技術</a>  <div class="mask">    <a href="#" class="button">X</a>  </div>  <!-- 底部發言框前端 -->  <div class="bottom">    <input class="content"></input>    <a href="#" class="send">發表言論</a>  </div>

css代碼:

?
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 html,body{    background-image:url("images/208.jpg");    height:100%;//文字的顯示地區要設定好  }  div.mask{    position:fixed;    width:100%;    height:100%;    background-color:black;    opacity:0.5;    top:0px;    left:0px;  }  div.bottom{    width:100%;    height:77px;    background-color:#090909;    position:fixed;    bottom:0px;    left:0px;    text-align:center;    line-height:77px;  }  div.bottom input.content{    width:605px;    height:37px;    border:none;    border-radius:10px 0px 0px 10px;    font-size:16px;    font-family:‘Microsoft Yahei‘;  }  div.bottom a.send{    background-color:green;    color:#fff;    display:inline-block;    width:150px;    height:40px;    line-height:37px;    text-align:center;    position:relative;    left:-10px;    top:-2px;    border-radius:0px 10px 10px 0px;    text-decoration:none;    font-family:‘Microsoft Yahei‘;  }  div.mask a.button{    width:50px;    height:50px;    border-radius:30px;    background-color:#660000;    color:#fff;    position:fixed;    top:20px;    right:20px;    text-align:center;    line-height:50px;    font-size:30px;    font-family:‘Microsoft Yahei‘;    border:1px solid #fff;    text-decoration:none;    cursor:pointer;  }  div.text{    color:#fff;    position:fixed;    right:0px;    font-size:20px;    white-space: nowrap;  }

jQuery代碼:

?
123456789101112131415 $(‘a.send‘).click(function(){      //擷取內容,建立新元素,並設定位置追加到目標元素中      var val=$(‘input.content‘).val();      var $content=$(‘<div class="text">‘+val+‘</div>‘);      var top=Math.random()*$(document.body).height()-77;      $content.css(‘top‘,top);      $(‘div.mask‘).append($content);      //移動到最右側,直接刪除該元素      $content.animate({right:$(document.body).width()+100},8000,function(){        $(this).remove();      });    });    $(‘div.button‘).click(function(){      $(‘div.mask‘).hide(2000);    });

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援指令碼之家。

又一枚精彩的彈幕效果jQuery實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.