> php教程 > PHP开发 > 모바일 적응을 위한 여러 솔루션(3가지 솔루션)

모바일 적응을 위한 여러 솔루션(3가지 솔루션)

高洛峰
풀어 주다: 2016-12-05 13:03:19
원래의
5822명이 탐색했습니다.

1. js 적응을 직접 사용

1

2

3

4

5

6

7

8

9

10

11

12

(function (doc, win) {

var docEl = doc.documentElement,

resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',

recalc = function () {

var clientWidth = docEl.clientWidth;

if (!clientWidth) return;

docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';

};

if (!doc.addEventListener) return;

win.addEventListener(resizeEvt, recalc, false);

doc.addEventListener('DOMContentLoaded', recalc, false);

})(document, window);

로그인 후 복사

예: 100px=1rem;10px=0.1rem;1px=0.01rem;

2. js+less를 사용하여

1

2

3

4

5

6

7

8

(function (win) {

function setUnitA() {

document.documentElement.style.fontSize = document.documentElement.clientWidth / 10 + "px";

}

var h = null;

window.addEventListener("resize", function () { clearTimeout(h); h = setTimeout(setUnitA, 300); }, false);

setUnitA();

})(window);

로그인 후 복사

less를 조정합니다. 파일 상단에 @unit: 750/10rem을 정의한 다음 CSS 전체 파일의 단위 @unit을 직접 사용하세요.

예: 100px=100/@unit;10px=10/@unit;1px=1/@unit;

3. 적응을 덜 사용합니다.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

html {

font-size: 20px;

}

@media only screen and (min-width: 401px) {

html {

font-size: 25px !important;

}

}

@media only screen and (min-width: 428px) {

html {

font-size: 26.75px !important;

}

}

@media only screen and (min-width: 481px) {

html {

font-size: 30px !important;

}

}

@media only screen and (min-width: 569px) {

html {

font-size: 35px !important;

}

}

@media only screen and (min-width: 641px) {

html {

font-size: 40px !important;

}

}

@unit: 40rem;

로그인 후 복사

예: 100px=100/@unit;10px=10/@unit;1px=1/@unit;


관련 라벨:
js
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿