CoffeeScript - detect if current scroll position is below div

元气小坏坏 提交于 2019-12-12 02:34:22

问题


I would like to detect when the user scrolls past a certain point in the window.

[Meta]
X
scroll below = alert() 

I'm quite new to CoffeeScript, so any help would be great!

What I currently have is this:

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

And no alert is showing up. Any tips?

Update I suspect that my problem have to do with my two variables. Here is an example:

$("#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')
)

来源:https://stackoverflow.com/questions/18292183/coffeescript-detect-if-current-scroll-position-is-below-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!