/*
INITIALIZE VIEWPORT FUNCTION
- Author/Contributor: GML/BJW
- Requires jQuery
- EXAMPLE USAGE: initViewport("div#main", "meta[name='viewport']");
*/
initViewport = function(mainElemSelector, metaViewportSelector) {
if (mainElemSelector === null) {
mainElemSelector = "body div:first";
}
if (metaViewportSelector === null) {
metaViewportSelector = "meta[name='viewport']";
}
var objMetaViewport = $(metaViewportSelector),
intScreenWidth = screen.width,
intScreenOrientation = Math.abs(window.orientation),
intMinWidth = parseFloat($(mainElemSelector).css("width")),
/* intMinWidth = parseFloat($(mainElemSelector).css("min-width")), */
intRatio = intScreenWidth / intMinWidth,
strContent = "width=device-width, user-scalable=yes, ";
/* For debugging/testing */
alert("width=" + intScreenWidth + ", orientation=" + intScreenOrientation + ", ratio= " + intRatio);
if (intRatio > 0 && intRatio < 1 && intScreenOrientation !== 90) {
strContent = strContent + "minimum-scale=" + intRatio + ", maximum-scale=" + intRatio;
} else {
strContent = strContent + "minimum-scale=1, maximum-scale=1";
}
objMetaViewport.attr("content", strContent);
/* For debugging/testing */
alert(strContent);
};
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.