元素上的锤子可以防止-webkit-overflow-scroll:触摸子元素

时间:2014-02-27 13:40:01

标签: javascript hammer.js

我不知道这是不是一个错误,如果我做错了或者这只是HammerJS的正常行为,但是我正在尝试使用HammerJS为App创建一个滑出菜单(Facebook风格)我是与Cordova一起发展。

到目前为止,除了一个之外我一切正常:HammerJS杀死附加了HammerJS的元素的子元素的原生-webkit-overflow-scroll: touch;。我和juste一起玩过关于我在doc中找到的所有选项,但似乎无法使用它。

有什么想法吗?

这是我在coffescript中的代码

Hammer($page, {
        transform_always_block: false,
        drag_block_horizontal: false,
        drag_block_vertical:false
        })
        .on('dragstart', (event)->
            #event.gesture.preventDefault()
            #event.gesture.stopPropagation()
            direction  = event.gesture.direction
            $mainMenu.show()
            $('.UIViewContainer').css(overflow: 'hidden')
            if direction is 'left'
                $('#homeDisableOverlay').animate({
                    opacity: 0
                }, 500, 'ease', ->
                    $(@).hide()
                )
        )
        .on('dragright', (event)->
            event.gesture.stopPropagation()
            direction  = event.gesture.direction
            offsetLeft = $page.offset().left
            scaleMenu  = 0.9 + scaleStep * offsetLeft

            if scaleMenu > 1
                scaleMenu = 1
            if scaleMenu < 0.9
                scaleMenu = 0.9

            if((offsetLeft > sidebarOffset) or (!App.PageDrag)) then return false

            if !App.sidebar
                offset = event.gesture.deltaX
                if offset > sidebarOffset then offset = sidebarOffset
                $page.animate({ translate3d: offset + 'px, 0, 0'}, 0)
                $mainMenuTable.animate({ scale: scaleMenu}, 0)
        )
        .on('dragleft', (event)->
            event.gesture.stopPropagation()
            event.stopPropagation()

            console.log direction

            offsetLeft = $page.offset().left
            scaleMenu  = 0.9 + scaleStep * offsetLeft

            if scaleMenu > 1
                scaleMenu = 1
            if scaleMenu < 0.9
                scaleMenu = 0.9

            if((offsetLeft <= 0) or (!App.PageDrag)) then return false

            if App.sidebar
                offset = sidebarOffset + event.gesture.deltaX
                if offset < 0 then offset = 0
                $page.animate({ translate3d: offset + 'px, 0, 0'}, 0)
                $mainMenuTable.animate({ scale: scaleMenu}, 0)

        )
        .on('dragend', (event)->
            event.gesture.stopDetect()
            event.gesture.preventDefault()
            event.gesture.stopPropagation()
            speed = 300 / event.gesture.velocityX
            if speed > 300 then speed = 300


            if(event.gesture.direction is 'right' and !App.sidebar)
                if((event.gesture.deltaX > sidebarOffset/2) or (event.gesture.velocityX > 0.4))
                    $page.animate({ translate3d: sidebarOffset + 'px, 0, 0'}, speed, 'ease')
                    $mainMenuTable.animate({ scale: 1}, speed, 'ease')
                    App.sidebar = true
                    $('#homeDisableOverlay').show().animate({
                            opacity: 0.3
                        }, 200, 'ease')
                else
                    $page.animate({ translate3d: '0, 0, 0'}, 200, 'ease')
                    $mainMenuTable.animate({ scale: 1}, 200, 'ease')
                $('.UIViewContainer').css(overflow: 'hidden')
                scaleMenu = 1

            else
                if((event.gesture.deltaX < sidebarOffset/2) or (event.gesture.velocityX > 0.4))
                    $page.animate({ translate3d: '0, 0, 0'}, speed, 'ease')
                    $mainMenuTable.animate({ scale: 0.9}, speed, 'ease')
                    App.sidebar = false
                    setTimeout(->
                        document.getElementById('mainMenuScroll').scrollTop = 0
                    ,speed)
                else
                    $page.animate({ translate3d: sidebarOffset + 'px, 0, 0'}, 200, 'ease')
                    $mainMenuTable.animate({ scale: 0.9}, 200, 'ease')
                    setTimeout(->
                        document.getElementById('mainMenuScroll').scrollTop = 0
                    ,200)
                $('.UIViewContainer').css(overflow: 'auto')
                scaleMenu = 0.9
        )

1 个答案:

答案 0 :(得分:0)

是的,这显然是对HammerJS的预期行为:

https://github.com/hammerjs/hammer.js/issues/250

我目前正试图找到一种替代方案,让全局工作的捏合手势不会破坏iOS上的滚动。