Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let nico = new nicoJS({
nico.listen()

// コメント送信
nico.send('Hello World.', '色[option]', 'フォントサイズ[option]')
nico.send('Hello World.', '色[option]', 'フォントサイズ[option]', '表示位置[option]')
```

特定のコメントを流し続ける
Expand Down
2 changes: 1 addition & 1 deletion lib/nico.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 32 additions & 10 deletions src/nico.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class nicoJS
@timer = null
@interval = null
@fps = 1000 / 30
@distime = 3 * 1000 / @fps
@step = 2 * 1000
@comments = []

Expand Down Expand Up @@ -48,25 +49,40 @@ class nicoJS
# @param text : コメント
# @param color : 色[option]
# @param font_size : フォントサイズ[option]
# @param layout : 位置[option]
##
send: (text, color, font_size) ->
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 }

##
# コメントを流す
Expand All @@ -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'

##
# コメントを待機
Expand Down