Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Automatically scale the entire viewport with some jquery stuff
- //
- // Need something like this in your CSS:
- //
- // html {
- // height: 1080px;
- // width: 1920px;
- // transform-origin: top left;
- // }
- function debounce(func, wait, immediate) {
- var timeout;
- return function () {
- var context = this, args = arguments;
- var later = function () {
- timeout = null;
- if (!immediate) func.apply(context, args);
- };
- var callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- if (callNow) func.apply(context, args);
- };
- };
- function set_size() {
- var tw = 1920;
- var th = 1080;
- var w = $(window).width();
- var h = $(window).height();
- var scale = 1;
- // width out by more than +/- 2%
- if (Math.abs(w / tw - 1) > 0.02) {
- scale = Math.max(w / tw, 0.25); // avoid going to crazy crash territory so clamp at 25% scaling
- }
- if (console) console.log("Auto sizing for resolution: " + w + "x" + h + ", scaling:" + scale);
- $('html').css('transform', 'scale(' + scale + ')');
- $('html').css('-ms-transform', 'scale(' + scale + ')');
- }
- $(function () {
- var debouncedResize = debounce(set_size, 500);
- $(window).resize(debouncedResize);
- set_size();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement