안녕하세요:) 개발자 우디입니다! 아래 내용 관련하여 작업 중이신 분들께 도움이되길 바라며 글을 공유하니 참고 부탁드립니다😊
(이번에 벨로그로 이사오면서 예전 글을 옮겨적었습니다. 이 점 양해 부탁드립니다!)
반응형 디자인에 대한 방법론은 찾아보니 여러 가지가 있었음
미디어 쿼리를 활용하는 방법
반응형을 위한 기본이자 핵심임
아래와 같은 방식으로 활용 → 타이틀의 텍스트 크기를 40px로 하되, 600px보다 작은 화면에서는 20px로 줄인다는 내용임
.title {
font-size: 40px;
}
@media (max-width: 600px) {
.title {
font-size: 20px;
}
}
반응형, 적응형 웹 디자인
메타 태그와 뷰포트를 활용한 방법
vw, vh를 활용한 방법
고민 및 테스트 끝에 vw, vh를 활용하기로 결정함
function createWindow() {
const primaryDisplayInfo = screen.getPrimaryDisplay();
win = new BrowserWindow({
width: Math.floor(primaryDisplayInfo.size.width),
maxWidth: Math.floor(primaryDisplayInfo.size.width),
minWidth: Math.floor(primaryDisplayInfo.size.width / 2),
height: Math.floor(primaryDisplayInfo.size.height),
maxHeight: Math.floor(primaryDisplayInfo.size.height),
minHeight: Math.floor(primaryDisplayInfo.size.height / 2),
...
}
const modalStyles = {
...
width: '508px',
height: '458px'
}
};
const modalStyles = {
...
width: '26.458vw',
height: '23.854vw',
},
};
아래의 엑셀 캡쳐 이미지는 px에서 vh, vw로 그리고 vh에서 vw로 변환하기 위한 수식이 적용된 엑셀 파일.
vw, vh가 적용되지 않는 경우에는 자체적으로 계산해서 값 할당해 줌.
utils.js - 1920을 기준으로 주어진 값을 사용자 해상도에 맞는 값으로 바꿔주는 함수 getResponsiveLength.
/**
* Apply the given number responsively
* @param {number} givenNum
*/
const getResponsiveLength = givenNum => {
return (givenNum * window.innerWidth) / 1920;
};
getResponsiveLength 활용 예시
...
import { formatDuration, getResponsiveLength, nFormatter } from '../../../utils';
...
focusPoint
.style('fill', this.FOCUS_POINT_COLOR_STR)
.style('stroke-width', 0)
.attr('rx', d => {
return getResponsiveLength(fillPointLength);
})
.attr('ry', d => {
return getResponsiveLength(fillPointLength / heightDivisor);
})
...
```
react-tooltip 라이브러리를 활용해 구현한 툴팁의 경우에도 vw, vh 가 잘 적용되지 않아서 별도로 함수 만들어서 사용해 줌
utils.js - 툴팁에 반응형 디자인 적용시키는 함수 applyTooltipResponsiveOffset.
/**
* apply responsive tooltip-offset
* @param {number} topVal
* @param {number} bottomVal
* @param {number} rightVal
* @param {number} leftVal
*/
const applyTooltipResponsiveOffset = (topVal, bottomVal, rightVal, leftVal) => {
const offsetResult = {};
const innerWidth = window.innerWidth;
if (topVal) {
offsetResult.top = (topVal * innerWidth) / 1920;
}
if (bottomVal) {
offsetResult.bottom = (bottomVal * innerWidth) / 1920;
}
if (rightVal) {
offsetResult.right = (rightVal * innerWidth) / 1920;
}
if (leftVal) {
offsetResult.left = (leftVal * innerWidth) / 1920;
}
return JSON.stringify(offsetResult);
};
applyTooltipResponsiveOffset 활용 예시
import {
...
applyTooltipResponsiveOffset,
} from '../../../utils';
<ReactTooltip id="videoAnalysisInfoModalVideoInfoImageTooltip" />
<div
...
data-offset={applyTooltipResponsiveOffset(0, 10, 90, 0)}
>