正文 3015字数 4,497阅读


阻止下拉刷新
/* prevent pull-to-refresh for Safari 16+ */ @media screen and (pointer: coarse) { @supports (-webkit-backdrop-filter: blur(1px)) and (overscroll-behavior-y: none) { html { min-height: 100.3%; overscroll-behavior-y: none; } } } /* prevent pull-to-refresh for Safari 9~15 */ @media screen and (pointer: coarse) { @supports (-webkit-backdrop-filter: blur(1px)) and (not (overscroll-behavior-y: none)) { html { height: 100%; overflow: hidden; } body { margin: 0px; max-height: 100%; /* or `height: calc(100% - 16px);` if body has default margin */ overflow: auto; -webkit-overflow-scrolling: touch; } /* in this case to disable pinch-zoom, set `touch-action: pan-x pan-y;` on `body` instead of `html` */ } } /* prevent pull-to-refresh for Chrome 63+ */ body{ overscroll-behavior-y: none; }
Run code
Cut to clipboard


    阻止前进后退手势
    /* currently there is NO SIMPLE WAY to prevent BackForwardNavigationGestures for Safari */ /* prevent "overscroll history navigation" for Chrome 63+ */ body{ overscroll-behavior-x: none; }
    Run code
    Cut to clipboard


      禁止手势缩放
      /* prevent pinch-zoom for Chrome 36+, Safari 13+ */ html { touch-action: pan-x pan-y; min-height: 100%; /* for Safari */ }
      Run code
      Cut to clipboard

        // prevent pinch-zoom for iOS Safari 9~12 if (window.GestureEvent && !('touchAction' in document.documentElement.style)) { document.documentElement.addEventListener('gesturestart', (e)=>{e.preventDefault()}, {passive: false, capture:true}); }
        Run code
        Cut to clipboard

          <!-- prevent pinch-zoom for Chrome, old Safari --> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
          Run code
          Cut to clipboard


            禁止双击缩放
            if (window.GestureEvent || (navigator.maxTouchPoints & 0xFF) > 0) { document.body.addEventListener('click', (e) => { if (!isInteractiveElement(e.target)) e.preventDefault(); }); } function isInteractiveElement(e) { let {nodeName} = e; if (nodeName === 'A' && e.hasAttribute('href') || ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'].includes(nodeName) && !e.disabled || nodeName === 'LABEL' && (e.htmlFor || e.querySelector('input,select,textarea') !== null) || ['IMG', 'OBJECT'].includes(nodeName) && e.useMap || ['AUDIO', 'VIDEO'].includes(nodeName) && e.controls || ['SUMMARY', 'IFRAME', 'EMBED'].includes(nodeName)) { return true; } return e.hasAttribute('tabindex') && e.tabIndex > -1; }
            Run code
            Cut to clipboard


              禁止iOS Safari其他默认行为
              禁止长按选中文本
              -webkit-user-select: none;
              Run code
              Cut to clipboard

                禁止长按弹出上下文菜单
                -webkit-touch-callout: none;
                Run code
                Cut to clipboard

                  禁止按钮/链接点击特效
                  -webkit-tap-highlight-color: transparent;
                  Run code
                  Cut to clipboard

                    禁止长按弹出上下文菜单
                    -webkit-touch-callout: none;
                    Run code
                    Cut to clipboard

                      禁止视频弹出悬浮窗口
                      <video playsinline></video>
                      Run code
                      Cut to clipboard