zoukankan      html  css  js  c++  java
  • 禁止橡皮筋效果

    
    
    let startY = 0
    let enabled = false
    let supportsPassiveOption = false
    try {
    let opts = Object.defineProperty({}, 'passive', {
    get: function () {
    supportsPassiveOption = true
    }
    })
    window.addEventListener('test', null, opts)
    } catch (e) {
    // console.log('false')
    }
    const handleTouchmove = function (evt) {
    let el = evt.target
    let zoom = window.innerWidth / window.document.documentElement.clientWidth
    if (evt.touches.length > 1 || zoom !== 1) {
    return
    }
    while (el !== document.body && el !== document) {
    let style = window.getComputedStyle(el)
    if (!style) {
    break
    }
    if (el.nodeName === 'INPUT' && el.getAttribute('type') === 'range') {
    return
    }
    let scrolling = style.getPropertyValue('-webkit-overflow-scrolling')
    let overflowY = style.getPropertyValue('overflow-y')
    // let height = parseInt(style.getPropertyValue('height'), 10)
    let isScrollable = scrolling === 'touch' && (overflowY === 'auto' || overflowY === 'scroll')
    let canScroll = el.scrollHeight > el.offsetHeight
    if (isScrollable && canScroll) {
    let height = el.clientHeight
    let curY = evt.touches ? evt.touches[0].screenY : evt.screenY
    let isAtTop = (startY <= curY && el.scrollTop === 0)
    let isAtBottom = (startY >= curY && el.scrollHeight - el.scrollTop === height)
    if (isAtTop || isAtBottom) {
    evt.preventDefault()
    }
    return
    }
    el = el.parentNode
    }
    evt.preventDefault()
    }
    const handleTouchstart = function (evt) {
    startY = evt.touches ? evt.touches[0].screenY : evt.screenY
    }
    const enable = function () {
    window.addEventListener('touchstart', handleTouchstart, supportsPassiveOption ? { passive: false } : false)
    window.addEventListener('touchmove', handleTouchmove, supportsPassiveOption ? { passive: false } : false)
    enabled = true
    }
    const disable = function () {
    window.removeEventListener('touchstart', handleTouchstart, false)
    window.removeEventListener('touchmove', handleTouchmove, false)
    enabled = false
    }
    const isEnabled = function () {
    return enabled
    }
    let testDiv = document.createElement('div')
    document.documentElement.appendChild(testDiv)
    testDiv.style.WebkitOverflowScrolling = 'touch'
    let scrollSupport = 'getComputedStyle' in window && window.getComputedStyle(testDiv)['-webkit-overflow-scrolling'] === 'touch'
    document.documentElement.removeChild(testDiv)
    if (scrollSupport) {
    enable()
    }
    let preventOverScroll = {
    enable: enable,
    disable: disable,
    isEnabled: isEnabled
    }

    export default preventOverScroll
    
    
  • 相关阅读:
    Nginx 反向代理多个后台服务端口
    微信小程序,横向布局,纵向布局
    Maven的标准settings.xml文件
    Springboot 复杂查询及SQL拼接笔记
    ElementUI 设置显示侧栏滚动条elscrollbar,隐藏横向滚动条
    让俺内牛满面的编辑器啊~
    Javascript 对话框 (遇到 Ajax Load无法加载问题)
    thinkpad s5 电源功率不足提示
    NAO机器人开发环境配置
    Choregraphe 2.8.6.23动作失效
  • 原文地址:https://www.cnblogs.com/QQPrincekin/p/11541211.html
Copyright © 2011-2022 走看看