Skip to content

Instantly share code, notes, and snippets.

@DracoBlue
Created February 12, 2012 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DracoBlue/1810322 to your computer and use it in GitHub Desktop.
Save DracoBlue/1810322 to your computer and use it in GitHub Desktop.
AutoScale to 320x480, part of swarmfight.com, released under the Public Domain
AutoScale = function(dom_element) {
var that = this;
this.dom_element = dom_element;
var style = dom_element.style;
var transform_property = (style.TransitionDuration === '' && 'Transform');
transform_property = transform_property || (style.MozTransitionDuration === '' && 'MozTransform');
transform_property = transform_property || (style.WebkitTransitionDuration === '' && 'WebkitTransform');
transform_property = transform_property || (style.OTransitionDuration === '' && 'OTransform');
transform_property = transform_property || (style.MsTransitionDuration === '' && 'MsTransform');
this.transform_property = transform_property;
jQuery(window).bind('resize', function() {
that.refresh();
});
that.refresh();
};
AutoScale.prototype.refresh = function()
{
this.dom_element.style[this.transform_property] = 'scale(0.1)';
var max_scale = Math.min((jQuery(window).height()/320), jQuery(window).width()/480);
this.dom_element.style[this.transform_property] = 'scale(' + max_scale + ')';
};
jsb.registerHandler('auto_scale', AutoScale);
<div class="viewport">
<input class="jsb_ jsb_auto_scale" type="hidden" value="" />
<div class="view">
Display! :)
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment