The following code zooms the page so that it matches 1024px = 100% if the available space is less. If there is enough space, the page is displayed as is.
https://jsfiddle.net/xgqw5bjo/3/
Please note that the version with the installation style via jQuery does not work, since jQuery processes the prefixes themselves, but in this solution I need to manage each of them.
~function () { var $window = $(window), $body = $("body"); var ie = document.documentMode; function updateSizes() { var width = $window.width(), scale = Math.min(width / 1024, 1); var style = $body[0].style; style.msZoom = ie === 8 || ie === 9 ? scale : 1; style.zoom = ie === 10 || ie === 11 ? 1 : scale; style.mozTransform = "scale(" + scale + ")"; style.oTransform = "scale(" + scale + ")"; style.transform = "scale(" + scale + ")"; } $window.resize(updateSizes); updateSizes(); }();
html { width: 100%; overflow: hidden; } body { margin: 0; transform-origin: top left; } @supports (transform: scale(1)) { body { -ms-zoom: 1 !important; zoom: 1 !important; } } div { width: 1024px; height: 128px; background: url(//i.stack.imgur.com/eMSCb.png) repeat-x; background: repeating-linear-gradient(to right, blue, red 256px); }
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div></div>
Theoretically, it should work as follows:
- IE 5.5 - 7 zoom
- IE 8 - 9 -ms-zoom
- IE 10 - 11 transform and ie
Edge 12+ transform and @supports
Opera 11.5 - 12.0 -o-transform
Opera 12.1 transform
Firefox 3.5 - 15 -moz-transform
- Firefox 16+ transform
Firefox 22+ transform (has @supports but no zoom )
Safari 4 - 8 zoom
Safari 9+ transform and @supports (appeared simultaneously)
Chrome 4 - 27 zoom
- Chrome 28 - 35 zoom (has
@supports but not transform yet) - Chrome 36+ transform and @supports
If I add -webkit-transform , it will start working in Safari 3.1 - 3.2, but it will slow down a lot of others.
In fact, for modern browsers, the result is obtained using transform and disgarding zoom . All modern live browsers (Edge, Firefox, Safari, Chrome) already have transform and @supports and comply with the standards, so the code will not be broken in the future.
Tested code in:
- IE 11
- Edge 15
- Opera 12.18
- Firefox 50
- Safari 5 (Win)
- Safari 10 (Mac)
- Chrome 54, 58
Browser Support Information:
Translation of my response to ruSO.
source share