0
这里的问题是,在我的Rails应用程序中,我编写了两个咖啡脚本文件,都需要window.onscroll fn。我的两个咖啡文件在Rails中相互干扰
当我一次一个实现它们时,两者都可以正常工作,但是当我包含这两个参数时,脚本停止工作。
这是第一个脚本
rightBarControl = ->
windowHeight = $(window).height()
scrollHeight = $(window).scrollTop()
rightBarWidth = $('#index_top_confession_div').width()
#20% of .main width
rightBarHeight = $('#index_top_confession_div').outerHeight()
rightBarOffset = $('#index_confessions').offset().left + $('#index_confessions').outerWidth()
rightBarTop = 75
#30 because .head is 30px high
if windowHeight - 75 < rightBarHeight
#Again including 30 because of .head
rightBarTop = windowHeight - rightBarHeight
if windowHeight + scrollHeight - 75 >= rightBarHeight
$('#index_top_confession_div').css
position: 'fixed'
left: rightBarOffset
top: rightBarTop
else
$('#index_top_confession_div').css
position: 'static'
left: rightBarOffset
top: rightBarTop
return
$('#search').addClass 'form-control'
$(window).scroll rightBarControl
#Run control on window scroll
$(window).resize rightBarControl
第二个脚本文件..
$(document).ready ->
if $('.pagination').length
$(window).scroll ->
console.log('hey');
url = undefined
url = $('.pagination .next_page').attr('href')
if url and $(window).scrollTop() > $(document).height() - $(window).height() - 200
$('.pagination').html '<img src = \'/uploads/loader/loader.gif\' alt=\'loading...\'/>'
return $.getScript(url)
return
return $(window).scroll()
return
嗯..点是在同一页面上运行..一个控制右边栏和一个控制无限滚动 –