Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.