Skip to content

Instantly share code, notes, and snippets.

@akshuvo
Created February 8, 2020 10:07
Show Gist options
  • Save akshuvo/b59ed41d32f1beea8a106733211d98d8 to your computer and use it in GitHub Desktop.
Save akshuvo/b59ed41d32f1beea8a106733211d98d8 to your computer and use it in GitHub Desktop.
Auto Scale With Screen Size
// body auto scale
jQuery(document).ready(function($){
if( window.outerWidth > 767 ){
$(window).on('resize',function(){
var baseW = 1920;
var docW = window.outerWidth;
var docH = $(document).height();
var ePos = $('.footerend').position().top;
var marginB = Math.min(docH-ePos);
scale = Math.min(docW/baseW);
$('body').css({
'-webkit-transform' : 'scale(' + scale + ')',
'-moz-transform' : 'scale(' + scale + ')',
'-ms-transform' : 'scale(' + scale + ')',
'-o-transform' : 'scale(' + scale + ')',
'transform' : 'scale(' + scale + ')'
});
console.log(baseW,docW,scale);
});
$(window).trigger('resize');
}
// Windwo load
$(window).load(function(){
if( window.outerWidth > 767 ){
$(window).on('resize',function(){
var docH = $(document).height();
var ePos = $('.footerend').position().top;
var marginB = Math.min(docH-ePos);
$('body').css({
'margin-bottom' : '-'+marginB+'px'
});
});
$(window).trigger('resize');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment