鼠标点击DIV外面消失

document.onclick = function (event) {
var e = event || window.event;
var elem = e.srcElement || e.target;
while (elem) {
if (elem != document) {
//当鼠标点击的是div
if (elem.id =="commentsBox") {
return;
}
elem = elem.parentNode;
} else {
self.setState({
display:'none'
})
return;
}
}
}
//绑定鼠标经过事件
$(document).on("mouseover","[id^=ql-comment]",function () {
let content = $(this).attr("ql-comment");
let author = $(this).attr("ql-comment-addon");
let yPosition = $(this).offset().top;
let xPosition = $(window).width()- $('#editor').offset().left-$('#editor').width() -$('#commentsBox').width()-20;
let display = self.state.showContentFlag ? 'block':'none'
self.setState({
userName:author,
content:content,
yPosition:yPosition,
xPosition:xPosition,
display:display
})

你可能感兴趣的:(鼠标点击DIV外面消失)