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
嗯..點是在同一頁面上運行..一個控制右邊欄和一個控制無限滾動 –