html. How to implement - when scaling a site (ctrl + scroll) so that the necessary block remains the original size?
2 answers
It is necessary to specify everything instead of px
in %
, for example width:10%
- Layout is not adaptive. And the necessary block in% will then be magnified not by scaling but by resizing the window, which is not desirable - Stanislav Sagan
|
var zoom = window.devicePixelRatio; zoomChanged(); // отлавливаем изменение зума window.onresize = function() { var z = zoom; zoom = window.devicePixelRatio; if (z !== zoom){ zoomChanged(); } } // накладываем антизум на нужный блок function zoomChanged(){ if (zoom === 1){ neededBlock.style.zoom = ''; return; } var antiZoom = Math.round(1 / zoom * 100000) / 100000; neededBlock.style.zoom = antiZoom * 100 + '%'; } // PS transform:scale(x) xреново работает
|