Prevent parent page from scrolling when mouse is over embedded iframe in Firefox

前端 未结 3 829
不知归路
不知归路 2020-12-16 15:42

...without limiting the scroll inside the iframe or the need to specifically name/tag all scrollable elements.

Imagine google maps widget embedded i

3条回答
  •  忘掉有多难
    2020-12-16 16:40

    I think that will solve your problem it solved mine

        var myElem=function(event){
      return $(event.toElement).closest('.slimScrollDiv')
    }
    
    $(document).mouseover(function(e){
         window.isOnSub=myElem(e).length>0
    
    
    
    })
    
    $(document).on('mousewheel',function(e){
      if(window.isOnSub){  
    console.log(e.originalEvent.wheelDelta);      
        if( myElem(e).prop('scrollHeight')-myElem(e).scrollTop()<=myElem(e).height()&&(e.originalEvent.wheelDelta<0)){
    
          e.preventDefault()
        } 
    
    
    }
    
    })
    

    replace '.slimScrollDiv' with the element selector you want to
    prevent parent scroll while your mouse is on it

    http://jsbin.com/cutube/1/edit?html,js,output

提交回复
热议问题