HTML5 draggable='false' not working in Firefox browser

后端 未结 4 1787
野的像风
野的像风 2020-12-16 12:28

I\'m simply trying to apply HTML5 draggable=\'false\' attribute to some images but it\'s not working in Firefox browser. In Chrome working fine but on Firefox, after sele

4条回答
  •  失恋的感觉
    2020-12-16 13:10

    Update of James Morrison's update: even the newer version doesn't seem to work anymore.

    I could sort out a similar issue with a check inside the addEventListener("dragstart",...) which you probably need to set in case you are playing with drag & drop. In my case:

    document.addEventListener("dragstart", function( event ) {
        if (event.target.parentNode.localName == 'li') {
          // console.log("In case it's inside a 
  • element, prevent the drag"); event.preventDefault(); } else { // code taken from a Mozilla example, replace with what you need: // store a ref. on the dragged elem dragged = event.target; // make it half transparent event.target.style.opacity = .5; } }, false);
  • To check for an the check would look something like if (event.target.localName == 'img') {...

    As per the OP request: all of the "html only" solutions I have tried were not working.

提交回复
热议问题