From 9a0d6a8a91ee6b6a61c05e3fd981e94e4a5a1233 Mon Sep 17 00:00:00 2001 From: yuta Date: Tue, 4 Jul 2017 20:06:56 +0900 Subject: [PATCH] =?UTF-8?q?add:=20=E4=BD=8D=E7=BD=AE=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- lib/nico.js | 2 +- src/nico.coffee | 42 ++++++++++++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 11f821f..82f2eb7 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ let nico = new nicoJS({ nico.listen() // コメント送信 -nico.send('Hello World.', '色[option]', 'フォントサイズ[option]') +nico.send('Hello World.', '色[option]', 'フォントサイズ[option]', '表示位置[option]') ``` 特定のコメントを流し続ける diff --git a/lib/nico.js b/lib/nico.js index 8651ee3..c3e5465 100644 --- a/lib/nico.js +++ b/lib/nico.js @@ -1 +1 @@ -var e,nicoJS;nicoJS=function(){function t(t){this.version="1.1.8",this.timer=null,this.interval=null,this.fps=1e3/30,this.step=2e3,this.comments=[],this.app=t.app,this.font_size=t.font_size||50,this.color=t.color||"#fff",this.width=t.width||500,this.height=t.height||300,this.render()}return t.prototype.render=function(){return this.app.style.whiteSpace="nowrap",this.app.style.overflow="hidden",this.app.style.position="relative",this.app.style.width=this.width+"px",this.app.style.height=this.height+"px",console.log("nicoJS@"+this.version),console.log(" ├─ author : yuki540"),console.log(" ├─ homepage : http://yuki540.com"),console.log(" └─ repository : https://github.com/yuki540net/nicoJS")},t.prototype.resize=function(t,e){return this.width=t,this.height=e,this.app.style.width=this.width+"px",this.app.style.height=this.height+"px"},t.prototype.send=function(t,e,i){var s,o,n;return i=i||this.font_size,e=e||this.color,t=t||"",o=this.width,n=Math.random()*(this.height-this.font_size),s=document.createElement("div"),s.innerHTML=t,s.style.position="absolute",s.style.left=o+"px",s.style.top=n+"px",s.style.fontSize=i+"px",s.style.textShadow="0 0 5px #111",s.style.color=e,this.app.appendChild(s),this.comments.push({ele:s,x:o,y:n})},t.prototype.flow=function(){var t,e,i,s,o;for(o=[],e=i=0,s=this.comments.length;0<=s?is;e=0<=s?++i:--i)t=-1*this.comments[e].ele.getBoundingClientRect().width,this.comments[e].x>t?(this.comments[e].x-=4,o.push(this.comments[e].ele.style.left=this.comments[e].x+"px")):o.push(void 0);return o},t.prototype.listen=function(){return this.stop(),this.timer=setInterval(function(t){return function(){return t.flow()}}(this),this.fps)},t.prototype.loop=function(t){var e,i;return e=0,i=t.length,this.listen(),this.send(t[e++]),this.interval=setInterval(function(s){return function(){return is;e=0<=s?++i:--i)"naka"===this.comments[e].lay?(t=-1*this.comments[e].ele.getBoundingClientRect().width,this.comments[e].x>t?(this.comments[e].x-=4,n.push(this.comments[e].ele.style.left=this.comments[e].x+"px")):n.push(void 0)):this.comments[e].timer + send: (text, color, font_size, layout) -> + lay = layout || 'naka' font_size = font_size || @font_size color = color || @color text = text || '' - x = @width - y = Math.random() * (@height - @font_size) ele = document.createElement 'div' ele.innerHTML = text ele.style.position = 'absolute' - ele.style.left = x + 'px' - ele.style.top = y + 'px' ele.style.fontSize = font_size + 'px' ele.style.textShadow = '0 0 5px #111' ele.style.color = color + switch lay + when 'ue' + ele.style.textAlign = 'center' + ele.style.top = '0' + ele.style.right = '0' + ele.style.left = '0' + when 'shita' + ele.style.textAlign = 'center' + ele.style.right = '0' + ele.style.left = '0' + ele.style.bottom = '0' + else + x = @width + y = Math.random() * (@height - font_size) + ele.style.left = x + 'px' + ele.style.top = y + 'px' + @app.appendChild ele - @comments.push { ele: ele, x: x, y: y } + @comments.push { ele: ele, x: x, y: y, lay: lay, timer: 0 } ## # コメントを流す @@ -75,10 +91,16 @@ class nicoJS len = @comments.length for i in [0...len] - end = @comments[i].ele.getBoundingClientRect().width * -1 - if @comments[i].x > end - @comments[i].x -= 4 - @comments[i].ele.style.left = @comments[i].x + 'px' + if @comments[i].lay == 'naka' + end = @comments[i].ele.getBoundingClientRect().width * -1 + if @comments[i].x > end + @comments[i].x -= 4 + @comments[i].ele.style.left = @comments[i].x + 'px' + else + if @comments[i].timer < @distime + @comments[i].timer++ + else + @comments[i].ele.style.display = 'none' ## # コメントを待機