index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. let imgSizeAuto = function(){
  2. let viewHeight = document.body.offsetHeight;
  3. let viewWidth = document.body.offsetWidth;
  4. let imgEles = document.getElementsByClassName('img');
  5. let fontsize,ratefont = 0.259;
  6. if(viewWidth <= 1450){
  7. let rateHs = [0.047,0.113,0.069,0.089,0.089,0.089];
  8. let rateWs = [0.297,0.263,0.391,0.139,0.139,0.139]
  9. for(let i = 0; i < imgEles.length; i++){
  10. if(i <= rateHs.length){
  11. let newWidth = viewWidth * rateWs[i];
  12. imgEles[i].width = newWidth;
  13. // console.log(imgEles[i].width);
  14. }
  15. if(i == 3){
  16. fontsize = ratefont * imgEles[i].height;
  17. console.log(fontsize);
  18. }
  19. }
  20. let buttons = document.getElementsByClassName('buttons');
  21. for(let b of buttons){
  22. b.style.fontSize = fontsize + 'px';
  23. }
  24. }else{
  25. let buttons = document.getElementsByClassName('buttons');
  26. for(let b of buttons){
  27. b.style.fontSize = '22px';
  28. }
  29. }
  30. }
  31. imgSizeAuto();
  32. window.onresize = imgSizeAuto;