我想在頁面準備就緒時動態更改我的div高度。 (的document.ready)。那麼我應該使用什麼正確的Jquery Mobile頁面事件?正確的頁面事件使用Jquery Mobile修改CSS
嘗試使用pagebeforeshow和pageshow事件。
Pagebeforeshow事件
$(document).on 'pagebeforeshow', ->
page_id = $.mobile.activePage[0].id
if page_id == "brands"
maxHeight = Math.max.apply(null, $(".product_descriptions").map(->
$(this).height()
).get())
$(".product-image").css("height", maxHeight)
$(".circle-container").css("height", maxHeight)
maxHeight返回0
Pageshow事件
$(document).on 'pageshow', ->
page_id = $.mobile.activePage[0].id
if page_id == "brands"
maxHeight = Math.max.apply(null, $(".product_descriptions").map(->
$(this).height()
).get())
$(".product-image").css("height", maxHeight)
$(".circle-container").css("height", maxHeight)
maxHeight將返回正確的值。
雖然pageshow事件返回正確的值,所有元素將顯示第一則只的.css功能解僱。我可以看到.css事件被觸發,在移動設備上看起來很奇怪(屏幕彈跳)。
有沒有解決方法?
'pagebeforeshow'應該給你正確的高度,因爲頁面是完全建立。也許你應該在選擇器中更具體地指出$(「#brands .product_descriptions」) – Omar