Skip to content

Commit 8c2e60d

Browse files
committed
Fix overlay totoz positioning
Positioning was previously using the jQuery offset() method to compute the position. This method returns the absolute position of the element relative to the whole document, but the values are then used to set the absolute position (top and left CSS properties) of the totoz element. These properties apply based on the closest positioned parent, which in this case is the <body> element. Due to this, when the document is larger than the max-width of the <body> element (150ex) the overlay image was being pushed further right by half the difference. For instance, if the window is 1600px wide, and the body reaches its max width at 1213px in my case, the overlay is being displayed (1600-1213)/2 = 193px to the right of the intended position. We fix this issue by using the jQuery position() instead, which according to the documentation returns the absolute position of the element relative to the offset parent, in this case the <body> element. We also explicitly position the totoz below the [:...] anchor.
1 parent 35f31fb commit 8c2e60d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

app/assets/javascripts/chat.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ class Chat
144144
.css(display: "none", position: "absolute")
145145
.append("<img src=\"#{@totoz_url}#{totozName}\"/>")
146146
@totoz.append totoz
147-
offset = $(event.target).offset()
148-
[x, y] = [offset.left, offset.top]
149-
totoz.css "z-index": "15", display: "block", top: y + 20, left: x + 20
147+
position = $(event.target).position()
148+
[x, y] = [position.left, position.top + event.target.offsetHeight]
149+
totoz.css "z-index": "15", display: "block", top: y + 5, left: x + 5
150150

151151
destroyTotoz: (event) =>
152152
totozId = encodeURIComponent(event.target.getAttribute("data-totoz-name")).replace(/[%']/g, "")

0 commit comments

Comments
 (0)