Skip to content

Instantly share code, notes, and snippets.

@manuelcanga
Created January 7, 2022 19:23
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 manuelcanga/a4976b1327621741a66e4893afeb1d5a to your computer and use it in GitHub Desktop.
Save manuelcanga/a4976b1327621741a66e4893afeb1d5a to your computer and use it in GitHub Desktop.
Ajustar zoom al ancho de la pantalla (jquery / vanilla)
jQuery(document).ready(function($){
nsZoomZoom();
$( window ).resize(function() {
nsZoomZoom();
});
function nsZoomZoom() {
htmlWidth = $('html').innerWidth();
bodyWidth = 1000;
if (htmlWidth < bodyWidth)
scale = 1
else {
scale = htmlWidth / bodyWidth;
}
// Req for IE9
$("body").css('-ms-transform', 'scale(' + scale + ')');
$("body").css('transform', 'scale(' + scale + ')');
}
});
body {
position: absolute;
left: 25%;
top: 100%;
}
var trasweb = {};
trasweb.getSize = function () {
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight || e.clientHeight || g.clientHeight;
return {"x": x, "y": y};
};
function zoom_trasweb() {
var window_width = document.documentElement.clientWidth;
var body_width = document.getElementsByTagName('body')[0].childNodes[0].clientWidth + 100;
if (window_width <= body_width) {
var scaleX = 1;
var scaleY = 1;
}else {
var scaleX = window_width / body_width;
console.log(window_width, body_width, scaleX);
var window_height = document.documentElement.clientHeight;
var body_height = document.getElementsByTagName('body')[0].childNodes[0].clientHeight;
if(window_height < body_height) {
var scaleY = body_height / window_height;
}else {
var scaleY = window_height / body_height;
}
console.log(window_height, body_height, scaleY);
}
document.body.style['transform'] = 'scale(' + scaleX + ', ' + scaleY+ ' )';
if(scaleX !== 1 ) {
var margin_top = body_height * scaleY;
console.log(margin_top);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment