admin管理员组

文章数量:1430487

dragstart event isn't firing on chrome browser...I want to set the state to true on mouse drag event. so i add the document.addeventlistener('dragstart', this.dragstart) to the mousedown method like below,

ponentDidMount() {
    document.addEventListener('mousedown', this.mousedown);
}

ponentWillUnMount() {
    document.addEventListener('mousedown', this.mousedown);
}

dragstart = () => {
   console.log("dragstart");
}

mousedown = e => {
    console.log("mousedown"); 
    document.addEventListener('dragstart', this.dragstart);
}

Could someone help me with this. Thanks.

dragstart event isn't firing on chrome browser...I want to set the state to true on mouse drag event. so i add the document.addeventlistener('dragstart', this.dragstart) to the mousedown method like below,

ponentDidMount() {
    document.addEventListener('mousedown', this.mousedown);
}

ponentWillUnMount() {
    document.addEventListener('mousedown', this.mousedown);
}

dragstart = () => {
   console.log("dragstart");
}

mousedown = e => {
    console.log("mousedown"); 
    document.addEventListener('dragstart', this.dragstart);
}

Could someone help me with this. Thanks.

Share Improve this question edited Mar 4, 2019 at 20:37 stackoverflow_user asked Mar 4, 2019 at 20:22 stackoverflow_userstackoverflow_user 2896 silver badges20 bronze badges 2
  • 1 What is render () { mousedown = e => {? It's not normal JSX construction. You should return ponents in render method – nucleartux Commented Mar 4, 2019 at 20:25
  • edited the question. had a typo – stackoverflow_user Commented Mar 4, 2019 at 20:29
Add a ment  | 

1 Answer 1

Reset to default 4

The ondragstart event occurs when the user starts to drag an element or text selection, but I don't think it will fire on a mousedown. As well, the element needs to be draggable.

<p draggable="true">

本文标签: javascriptDragstart event not firing reactjsStack Overflow