我在我的jQuery Mobile网站头部有一个图像,我自动调整大小以便填满屏幕。在我的页面上有一个用户登录的子页面。但是在这个页面上,图片的大小调整不起作用。jQuery/JavaScript不支持在支持jQuery Mobile的网页上的子页面上工作
因为我正在搜索解决方案,我已经发现它是由jQuery Mobile引起的,它只允许jQuery在第一个data-role =“page”div内工作。但是,当我尝试每种解决方案时,他们都不会工作。
你们能帮我找到解决办法吗?
我的代码(在很短的复制/粘贴示例):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WHY DON'T YOU WORK?</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script>
window.onresize = function (event) {
resizeimage();
}
window.onload = function (event) {
resizeimage();
}
function resizeimage() {
var img = document.getElementById('headerimage');
var oldwidth = img.naturalWidth;
var oldheight = img.naturalHeight;
var newwidth = $(window).width();
var newheight = oldheight/oldwidth * newwidth;
img.width = newwidth;
img.height = newheight;
}
</script>
</head>
<body>
<div class="PageDiv" data-role="page" data-add-back-btn="true" id="FrontPage">
<div class="HeaderDiv" data-role="header" data-position="fixed">
<img id="headerimage" name="headerimage" src="images/PSO_Banner_960x89.png" />
</div>
<div class="ContentDiv" data-role="content" data-theme="a">
CONTENT #1
<a href="#LoginPage">LoginPage</a>
</div>
<div class="FooterDiv" data-role="footer" data-position="fixed">
FOOTER
</div>
</div>
<div class="PageDiv" data-role="page" data-add-back-btn="true" id="LoginPage">
<div class="HeaderDiv" data-role="header" data-position="fixed">
<img id="headerimage" name="headerimage" src="images/PSO_Banner_960x89.png" />
</div>
<div class="ContentDiv" data-role="content" data-theme="a">
CONTENT #2
<a href="#FrontPage">FrontPage</a>
</div>
<div class="FooterDiv" data-role="footer" data-position="fixed">
FOOTER
</div>
</div>
</body>
</html>
仍在寻找解决方案...
代码建议:'$(窗口) 。对('LOA d resize',resizeimage)' – Johan