       break
     parent = parent.offsetParent
 
-  el_bottom = el_top + h 
+  el_bottom = el_top + vh 
 
-  topVisible =    -slop * h < el_top && el_top < h * 2 * slop
-  bottomVisible = -slop * h < el_bottom && el_bottom < h * 2 * slop    
+  topVisible =    el_top    > -slop * vh  &&  el_top    < vh + slop * vh
+  bottomVisible = el_bottom > -slop * vh  &&  el_bottom < vh + slop * vh
+
   visible = topVisible || bottomVisible
 
   visible
+
 
 
 sense_viewport_visibility_changes = ->

    scrollY = window.scrollY 
    innerHeight = window.innerHeight 

    # if performance tuning, this could be improved by doing a binary search in els 
    # (assuming sorted by offsetY) to find the visible elements more efficiently
    for el in els 
      slop = parseInt(el.getAttribute('data-receive-viewport-visibility-updates') or 1)
      visible = is_el_visible el, scrollY, innerHeight, slop

      state = fetch el.getAttribute 'data-component'
      if !state.in_viewport? || state.in_viewport != visible 
        state.in_viewport = visible 
        save state

  update_scheduled = false


update_scheduled = false 


window.is_el_visible = (el, scrollY, viewport_height, slop) ->
  slop ?= 1
  slop -= 1
  el_top = -scrollY
  vh = viewport_height

  parent = el 
  while (true)
