본문 바로가기

ESC눌러서 모달창 닫기, 배열을 querystring파라미터로 전달하기

by limew 2023. 9. 12.

ESC눌러서 모달창 닫기

useEffect(() => {
    window.addEventListener('keydown', (e: KeyboardEvent) => {
      if (e.key === 'Escape') {
        onClose();
      }
    });
    return () => window.removeEventListener('keydown', () => onClose);
  }, [onClose]);

 

배열을 querystring파라미터로 전달하기

JSON으로 serialize할 수 있다

myArray = ['aaa', 'bbb', 'ccc'];
var arrStr = encodeURIComponent(JSON.stringify(myArray)); // '%5B%22aaa%22%2C%22bbb%22%2C%22ccc%22%5D'
$('#myLink').attr({ href: '/myLink?array=' + arrStr });

 

 

?id=1&gender=FEMALE

 

 

현재 위치 스크롤 멈추고 모달창 마스크 꽉 차게하기

현재스크롤 위치를 top으로 한다

position: absolute;
top: window.scrollY
style={{ top: window.scrollY, left: '50%', transform: 'translate(-50%, 20%)' }}

 

 

현재 스크롤바의 위치알기

window.scrollY

 

스크롤 disable, able하기

window.body.style.overflow = 'hidden'

 

 

'' 카테고리의 다른 글

React로 WebSocket 통신해보기 (client, server)  (0) 2024.04.16
쿠키 세션 토큰 JWT  (0) 2023.06.30
CORS  (0) 2023.06.04