用于文件onMouseDown的函数

问题描述 投票:0回答:1

我具有输入类型作为文件。我正在为其定义onMouseDown函数。按顺序更改文件预览的位置。出现以下错误:TypeError:无法设置未定义属性'left'

 <input 
     type="file"
     className="file"
     id="file-browser-input"
     name="file-browser-input"
     ref ={input=>this.fileInput=input}
     onDragOver={(e)=>{
     e.preventDefault();
     e.stopPropagation();
     }
    }
     onDrop={this.onFileLoad.bind(this)
     onChange={this.onFileLoad.bind(this)}
     onMouseDown={this.catchItem.bind(this)} 
/>

catchItem(e) {

    this.style.left = e.pageX - this.clientWidth / 2 + "px";
    this.style.top = e.pageY - this.clientHeight / 2 + "px";
    this.onmousemove = function(e) {
    this.style.left = e.pageX - this.clientWidth / 2 + "px";
    this.style.top = e.pageY - this.clientHeight / 2 + "px";
    }
    this.onmouseup = function() {
    this.onmousemove = null; // onmouseup event [ redirect mousemove event signal to null instead of the 
    drag-able element]
        }
      }
reactjs file mouseevent preview onmousedown
1个回答
0
投票

似乎this.style未定义

© www.soinside.com 2019 - 2024. All rights reserved.