6
我有下面的咖啡腳本,除了圖像需要一段時間加載它之前運行圖像加載之前運行,然後沒有所需的效果的作品:改編一個咖啡腳本來使用window.onload
ready = ->
jQuery ->
$('.box').find('img').each ->
imgClass = if @width/@height > 1 then 'wide' else 'tall'
$(this).addClass imgClass
return
return
$(document).ready(ready)
$(document).on('page:load', ready)
我怎樣才能運行我的功能只有在整個窗口加載後?
我最好的嘗試,到目前爲止看起來像
window.onload = ->
$('.box').find('img').each ->
imgClass = if @width/@height > 1 then 'wide' else 'tall'
$(this).addClass imgClass
return
return
,但它不工作。我也嘗試了其他幾種可能性,但我無法弄清楚什麼是錯的。
我的問題與this one不一樣,因爲我不想等到所有的咖啡文本都加載完畢,我想等到我的網頁中的所有圖像都加載完畢。
[coffeescript是否有類似於瀏覽器的onLoad事件]的可能重複(http://stackoverflow.com/questions/6656951/does-coffeescript-have-an-onload-like-event-for-the-browser ) –
絕對不是重複。請參閱我的編輯解釋原因。 – Dennis
感謝您的澄清。 –