我有一个函数可以使用javascript来平衡旧版浏览器的元素高度。问题是由于ajax内容,我必须以3秒的间隔运行该功能。我无法在内容更新上使用回调函数,因为它构建到我无法触及的CMS中。
我有以下coffeescript文件:
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)
我最初的想法是以这样的间隔触发函数:
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)
但这不起作用,任何想法?
答案 0 :(得分:2)
setInterval (=> @equalColumnHeight()), 3000
setInterval
接受第一个参数的函数,但是传递equalColumnHeight
的结果