How do I prevent drag on a child, but allow drag on the parent?

前端 未结 6 1063
情深已故
情深已故 2020-12-07 00:33

I have a div which the user can drag, inside that div is a span with some text which I want to allow the user to select (thus they cannot drag it). How do I allow the div to

6条回答
  •  心在旅途
    2020-12-07 01:17

    You can change the child element to draggable and prevent default when ondragstart, this will leave the regular behavior on the child element and the parent will still be draggable

    function drag(e){ if(e.target.type=="range")e.preventDefault();/*rest of your code*/  }
    

    html:

    
    

提交回复
热议问题