2014-02-27 130 views
4

我不知道這是一個錯誤,如果我做錯了什麼或者這只是HammerJS的正常行爲,但我試圖使用HammerJS爲我正在與科爾多瓦開發的應用程序製作滑出菜單(Facebook風格)。錘上元素防止-webkit溢出滾動:觸摸子元素

到目前爲止,我已經得到了一切正常工作,除了一個:HammerJS殺死了附有HammerJS的元素的子元素的本地-webkit-overflow-scroll: touch;。我已經充分利用了我可以在文檔中找到的所有選項,但似乎無法實現這一功能。

任何想法?

這是我在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 
     ) 

回答