CoffeeScript - 检测当前滚动位置是否低于div

时间:2013-08-17 18:43:29

标签: javascript ruby-on-rails coffeescript

我想检测用户滚动浏览窗口中的某个点的时间。

[Meta]
X
scroll below = alert() 

我对CoffeeScript很陌生,所以任何帮助都会很棒!

我现在拥有的是:

$("#area_1").bind('scroll', ->
  scrollPosition = $(this).scrollTop() + $(this).outerHeight()
  divTotalHeight = $(this)[0].scrollHeight()
  if (scrollPosition >= divTotalHeight)
    alert('end reached')
  )

没有警报出现。有什么提示吗?

更新 我怀疑我的问题与我的两个变量有关。这是一个例子:

$("#area_1").bind($(window).scroll ->
  alert('before 1') # Gets called
  scrollPosition = $(this).scrollTop() + $(this).outerHeight()
  divTotalHeight = $(this)[0].scrollHeight()
  alert('before 2') # Never gets called
  if (1 == 1)
    alert('should get called but dosn't')
)

0 个答案:

没有答案
相关问题