-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.erb
30 lines (29 loc) · 965 Bytes
/
template.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<html>
<head>
<title>Chat</title>
<link rel="stylesheet" type="text/css" href="skin.css" />
</head>
<body>
<% chat.reverse.each_with_index do |i, index| %>
<section class="chatbox">
<div class="chatter_name"<% if index == chat.length - 1%> id="lastmsg"<% end %>><%= i[:name] %> <span class="timestamp"><%= i[:timestamp] %></span></div>
<div class="chat_text"><%= i[:chat] %></div>
</section>
<% end %>
<script>
var onBottom = false
function takeoffFromBottom() {
if (window.innerHeight - document.getElementById("lastmsg").getBoundingClientRect().y > -20) {
onBottom = true
} else {
onBottom = false
}
}
window.setTimeout((function() {
window.location.reload(true)
if (onBottom) { document.getElementById("lastmsg").scrollIntoView(true) }
}), 10000 )
document.addEventListener("scroll", function(event) { takeoffFromBottom() })
</script>
</body>
</html>