我在同步调整大小的事件时遇到了一些问题。基本上,$M.resize更新div的宽度(css),然后我希望$API.resize读取新的大小并相应地更新它的元素。但是,如果我设置了窗口调整大小事件(如下所示),然后立即触发窗口的调整大小事件,则$API.resize不会获得任何新的宽度信息-几乎就像$M.resize尚未完成更新一样。$API.resize通过$(“#main”).css(“width”)获得新的宽度信息;我可以让它工作的唯一方法是通过下面使用setTimeout的变通方法。有没有更好的方法来做这件事?
// on page load
$(function () {
$(window).resize(function () {
$M.resize();
$API.resize();
});
setTimeout(function () {
$(window).resize();
}, 100);
});
// $API.resize
function () {
var pageWidth = $M.width();
console.log("pageWidth = " + pageWidth);
$("#atmoGrid").css("width", pageWidth);
$(".atmoSector")
.css("width", pageWidth/5-2)
.css("height", pageWidth/5-2);
}
// $M.resize
function () {
// refresh screen dimensions
width = Math.min(screen.availWidth, window.innerWidth);
height = Math.min(screen.availHeight, window.innerHeight);
smallScreen = (width < smallWidth);
fontScale = (smallScreen) ? 3 : 1;
// check if screen is small
if (smallScreen) {
$("#main").css("width", "100%");
} else {
$("#main").css("width", smallWidth + "px")
}
$("#main").css("font-size", $M.font(18));
}
// $M.width
function () {
var width = $("#main").css("width");
return parseInt(width);
}发布于 2012-08-27 12:31:38
试试这个:
// on page load
$(function () {
$(window).resize(function () {
$M.resize();
});
});
// $API.resize
function (mWidth, mHeight) {
var pageWidth = mWidth;
console.log("pageWidth = " + pageWidth);
$("#atmoGrid").css("width", pageWidth);
$(".atmoSector")
.css("width", pageWidth/5-2)
.css("height", pageWidth/5-2);
}
// $M.resize
function () {
// refresh screen dimensions
width = Math.min(screen.availWidth, window.innerWidth);
height = Math.min(screen.availHeight, window.innerHeight);
smallScreen = (width < smallWidth);
fontScale = (smallScreen) ? 3 : 1;
// check if screen is small
if (smallScreen) {
$("#main").css("width", "100%");
} else {
$("#main").css("width", smallWidth + "px")
}
$("#main").css("font-size", $M.font(18));
$API.Resize(smallWidth, someheight);
}
// $M.width
function () {
var width = $("#main").css("width");
return parseInt(width);
}hth
https://stackoverflow.com/questions/12136089
复制相似问题