Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[JS] 모바일 크롬브라우저 당겨서 새로고침 끄기

2020-08-03 by 편리

최근에 워드프레스 테마나 다른 원페이지 슬라이더 작업을 좀 진행 중인데 모바일 크롬 브라우저에서 아래로 당기게 되면 페이지가 새로 고침되는 경우가 있어 은근 스트레스였는데 이걸 끌 수 있는 스크립트가 있어 공유한다.

/*
prevent pull-down-to-refresh of mobile chrome
https://stackoverflow.com/a/55832568
*/
(function() {
  var touchStartHandler,
      touchMoveHandler,
      touchPoint;
  // Only needed for touch events on chrome.
  if ((window.chrome || navigator.userAgent.match("CriOS"))
      && "ontouchstart" in document.documentElement) {
      touchStartHandler = function() {
          // Only need to handle single-touch cases
          touchPoint = event.touches.length === 1 ? event.touches[0].clientY : null;
      };
      touchMoveHandler = function(event) {
          var newTouchPoint;
          // Only need to handle single-touch cases
          if (event.touches.length !== 1) {
              touchPoint = null;
              return;
          }
          // We only need to defaultPrevent when scrolling up
          newTouchPoint = event.touches[0].clientY;
          if (newTouchPoint > touchPoint) {
              event.preventDefault();
          }
          touchPoint = newTouchPoint;
      };
      document.addEventListener("touchstart", touchStartHandler, {
          passive: false
      });
      document.addEventListener("touchmove", touchMoveHandler, {
          passive: false
      });
  }
})();

위 자바스크립트 코드를 적용해주면 터치를 아래로 당겨도 새로 고침이 되지 않는다. 그리고 추가적으로 원페이지 슬라이더 환경에서 위로 터치하게 되면 페이지 하단에 흰 색이든 바운스라고 해야할까? 원하지 않느 부분이 표시될 때가 있는데 아래 css 코드르 추가해주면 이것도 보이지 않게 된다.

html {
  overflow: hidden;
}

참고 : https://stackoverflow.com/a/55832568

Post navigation

Previous Post:

워드프레스 자식테마에서 부모테마 js 적용하지 않기

Next Post:

워드프레스 Contact Form 7 에 네이버 프리미엄 로그 적용하기

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • SK 세븐모바일 유심 셀프교체
  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes