Skip to content

Instantly share code, notes, and snippets.

@oreshinya
Last active December 27, 2015 22:09
Show Gist options
  • Select an option

  • Save oreshinya/7397229 to your computer and use it in GitHub Desktop.

Select an option

Save oreshinya/7397229 to your computer and use it in GitHub Desktop.
viewportが効かない場合の同様の表現をするためのscript。webに転がってるzoomでやる方式は、heightとかpositionとかいろいろ壊れるのでscaleでやってる。
window.ViewPortAdjuster = {
viewport_width: 320,
viewport_height: 480,
zoom_ratio: 1,
adjust: function() {
var that=this,portrait_width,landscape_width;
$(window).bind("resize", function(){
if(Math.abs(window.orientation) === 0){
if(/Android/.test(window.navigator.userAgent)){
if (!portrait_width) portrait_width = $(window).width();
}else{
portrait_width = $(window).width();
}
that.zoom_ratio = portrait_width/that.viewport_width;
}else{
if(/Android/.test(window.navigator.userAgent)){
if (!landscape_width) landscape_width = $(window).width();
}else{
landscape_width = $(window).width();
}
that.zoom_ratio = landscape_width/that.viewport_width;
}
var body = $("body");
body.css("-webkit-transform-origin", "0% 0%");
body.css("-webkit-transform", "scale("+that.zoom_ratio+")");
body.css("width", that.viewport_width+"px");
body.css("height", that.viewport_height+"px");
}).trigger("resize");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment