resizeBak.js 851 B

12345678910111213141516171819202122232425
  1. (function () {
  2. var designW = 320
  3. var designH = 508
  4. var designR = designW / designH
  5. var actualW = document.documentElement.clientWidth
  6. var actualH = document.documentElement.clientHeight
  7. var actualR = actualW / actualH
  8. var scale = (actualR > designR) ? (actualH / designH) : (actualW / designW)
  9. var style = 'width: ' + designW + 'px; height: ' + designH + 'px; -webkit-transform: scale(' + scale + '); transform: scale(' + scale + '); '
  10. if (actualW < designW) {
  11. if (actualR > designR) {
  12. style += 'margin-left: ' + (actualW - designW) / 2 + 'px;'
  13. } else {
  14. style += '-webkit-transform-origin: left; transform-origin: left;'
  15. }
  16. }
  17. var containers = document.getElementsByClassName('resize-container')
  18. var i
  19. for (i = 0; i < containers.length; i++) {
  20. containers[i].setAttribute('style', style)
  21. }
  22. })()