我在我的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