0

I have a function that equalise element heights on older browsers with javascript. The problem is that I have to run that function at a 3 second interval or so due to ajax content. I cant use the callback function on the content update since it is build into a CMS I cant touch.

I have the following coffeescript file:

class window.ApplicationController
  constructor: ->
    #fire code
    @equalColumnHeight()
  #......
  equalColumnHeight: ->
    console.log "equal height"
    colLeft = 0
    if @browserwidth > 1024
      colLeft = (@columnPageTreeNav + @columnSidebarA)
    colHeight = Math.max(colLeft, @columnPageTreeNav, @columnContent, @columnSidebarA, @columnSidebarB)
    $("#content, #sidebar_a, #sidebar_b").height colHeight
    $("#sidebar_a").css "top", (@columnPageTreeNav + 190)

My initial idea was to fire the function at an interval like this:

class window.ApplicationController
  constructor: ->
    #fire code
    @equalColumnHeight()
    setInterval @equalColumnHeight(), 3000
  #......
  equalColumnHeight: ->
    colLeft = 0
    if @browserwidth > 1024
      colLeft = (@columnPageTreeNav + @columnSidebarA)
    colHeight = Math.max(colLeft, @columnPageTreeNav, @columnContent, @columnSidebarA, @columnSidebarB)
    $("#content, #sidebar_a, #sidebar_b").height colHeight
    $("#sidebar_a").css "top", (@columnPageTreeNav + 190)

But that does not work, any ideas?

4

1 回答 1

2
setInterval (=> @equalColumnHeight()), 3000

setInterval接受第一个参数的函数,但您传递的结果equalColumnHeight

于 2012-08-09T09:18:12.607 回答