【发布时间】:2023-04-10 06:32:01
【问题描述】:
我想在页面准备好时动态更改我的 div 高度。 (document.ready)。那么我应该使用 Jquery Mobile 中的正确页面事件是什么?
尝试使用 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)
最大高度返回 0
页面显示事件
$(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")
标签: javascript jquery css jquery-mobile