jQuery:页眉高度在后续页面上返回0 [英] jQuery: Header height returns 0 on subsequent pages
问题描述
我不太了解我现在遇到的问题.我有以下代码:
I don't really understand the problem I am having now. I have this code:
$(document).on("pageshow", "[data-role=page]", function(){
var $height = $("[data-role=header]").height();
alert($height);
});
此代码在第一页(索引)上运行良好,实际上返回的警报值为50.但是,当我导航到其他页面时,除非进行完全刷新,否则警报返回的高度为0.
This code is working fine on the first page (index) and actually returns an alert with 50. However when I navigate to different pages, the alert returns a height of 0 unless I do a full refresh.
我也尝试过窗口onload函数,它返回0.我要做的是获取每个页面的页眉高度,并使用它正确对齐ui内容.
I tried window onload function too, it returns me 0. What I want to do is to get the height of the header for every page and use it to align ui-content properly.
任何人都可以向我解释发生了什么事以及正确的做法吗?除了字体和按钮外,标题中没有太多内容.
Can anyone explain to me what's going on and what is the right way to do this? There's not much in the header except for a font and a button.
推荐答案
您应明确指定您真正想要的页眉高度.检查以下代码,希望它对您有用.
You should explicitly specify which header height you really want. Check the following code, hope this works for you.
var $height = $("[data-role=header]:visible").height();
这篇关于jQuery:页眉高度在后续页面上返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!