Many contributors have pointed out that altering the screen resolution may not be a recommended approach and could even be unfeasible. However, adjusting the scale of the contents can help ensure they fit perfectly within your window.
The following code snippet was created for a web application intended for devices with a 1280x800 resolution. As the application was also occasionally used on a 1080p screen, some scaling adjustments were necessary to achieve a seamless fit. The code below demonstrates how this adjustment is implemented.
A fullscreen API wrapper (available at ) is utilized to enable the browser to enter full-screen mode via a button click, triggering automatic scaling simultaneously. A functional example of this implementation can be accessed here: http://jsfiddle.net/QT5Nr/5/
It's worth noting that the provided code currently relies on jQuery 1.8.3 and screenfull.js, but modifications can easily be made to eliminate these dependencies. The rationale behind overriding the jQuery offset function is explained in the accompanying comment at the top of the code block. Testing the impact of commenting out this segment in the jsFiddle and resizing the frame can provide further insights.
/*****************************************************************************************************************************************\
|** Scale elements to fit page **|
|*****************************************************************************************************************************************|
|** Because we created a static size layout for our target device, other devices may not display content optimally. To address this issue, **|
|** we adjust the scale of body elements to ensure they fit precisely within the available window space. **|
|** Additionally, we need to customize jQuery.fn.offset to rectify discrepancies in element positioning caused by scaling effects. **|
\*****************************************************************************************************************************************/
function EnableAutoScale() {
function AdjustScale() {
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var viewportWidth = $('#viewport').width();
var viewportHeight = $('#viewport').height();
var horizontalScale = windowWidth / viewportWidth;
var verticalScale = windowHeight / viewportHeight;
$(document.body).css('transform-origin', '0 0');
$(document.body).css('transform': 'scale(' + horizontalScale + ', ' + verticalScale + ')');
document.body.HorizontalScale = horizontalScale;
document.body.VerticalScale = verticalScale;
}
$(AdjustScale);
$(window).resize(AdjustScale);
// Override offset method to maintain functionality with the applied scale
jQuery.fn.originalOffset = jQuery.fn.offset;
jQuery.fn.offset = function () {
var offset = jQuery.fn.originalOffset.apply(this, arguments);
offset.left = offset.left / document.body.HorizontalScale;
offset.top = offset.top / document.body.VerticalScale;
return offset;
};
}
$(function () {
$('#fullscreen').click(function () {
$('#fullscreen').hide();
EnableAutoScale();
if (screenfull.enabled)
screenfull.toggle();
});
});