Created
January 7, 2022 19:23
-
-
Save manuelcanga/a4976b1327621741a66e4893afeb1d5a to your computer and use it in GitHub Desktop.
Ajustar zoom al ancho de la pantalla (jquery / vanilla)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + ')'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
position: absolute; | |
left: 25%; | |
top: 100%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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