websocket_handles.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //发送弹幕
  2. var Barrage = function()
  3. {
  4. this.sendData = null;
  5. this.barrage_html = '';
  6. this.dataParse = function(data)
  7. {
  8. return {
  9. posY :parseInt(Math.random() * (100 - 20)),
  10. avatar: data.avatar,
  11. nickname : data.nickname,
  12. msg:data.msg
  13. }
  14. };
  15. this.add = function(send_data){
  16. this.sendData = this.dataParse(send_data);
  17. return this;
  18. };
  19. this.send = function()
  20. {
  21. if(this.sendData)
  22. {
  23. if(this.sendData.msg != null) {
  24. this.barrage_html = '<div class="barrage" style="position:absolute;top:'+this.sendData.posY+'%"><img src="'+this.sendData.avatar+'">'+this.sendData.nickname+'说:<span class="price">'+this.sendData.msg+'</span></div>';
  25. }
  26. $('body').append(this.barrage_html);
  27. this.sendData = null;
  28. this.barrage_html = '';
  29. this.clear();
  30. return this;
  31. }
  32. else {
  33. console.log('没有弹幕可以发送');
  34. }
  35. };
  36. this.clear = function()
  37. {
  38. $('.barrage').on('webkitAnimationEnd',function(){
  39. $(this).remove();
  40. });
  41. return this;
  42. };
  43. };