Skip to content

Commit

Permalink
requestAnimationFrame goodness
Browse files Browse the repository at this point in the history
(keep tooltip properly positioned no matter what)
  • Loading branch information
pfitzseb committed May 11, 2017
1 parent faa8cde commit 0a12263
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/util/tooltip.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Tooltip
@oldOnMouseOut = @parent.onmouseout

@showOnHover()
@positionOverlay()

this

onDidShow: (f) ->
Expand All @@ -61,9 +63,7 @@ class Tooltip
show: ->
@view.style.display = 'block'
@emitter.emit 'didShow'
setTimeout ( =>
@positionOverlay()
@view.classList.remove 'dontshow'), 20
setTimeout ( => @view.classList.remove 'dontshow'), 20

destroy: ->
if document.body.contains @view
Expand Down Expand Up @@ -94,10 +94,16 @@ class Tooltip
hideTimer = setTimeout (=> @hide()), @hideDelay

positionOverlay: ->
bounding = @parent.getBoundingClientRect()
@view.style.bottom = document.documentElement.clientHeight - bounding.top + 'px'
switch @position
when 'left'
@view.style.left = bounding.left + 'px'
when 'right'
@view.style.left = bounding.left + bounding.width - @view.offsetWidth + 'px'
p = @parent
pos = @position
v = @view
positioner = ->
bounding = p.getBoundingClientRect()
v.style.bottom = document.documentElement.clientHeight - bounding.top + 'px'
switch pos
when 'left'
v.style.left = bounding.left + 'px'
when 'right'
v.style.left = bounding.left + bounding.width - v.offsetWidth + 'px'
window.requestAnimationFrame positioner
window.requestAnimationFrame positioner

0 comments on commit 0a12263

Please sign in to comment.