You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
1.1 KiB

// const DOM = (container) => {
// this.container = container;
// this.containerBounds = container.getBoundingClientRect();
// }
const DOM = {
getEventOffsetCoords: (evt, bounds) => {
const { pageX, pageY } = evt;
return {
evtX: (pageX - bounds.left),
evtY: (pageY - bounds.top)
};
},
addClass: (node, str) => {
node.className = node.className.split(' ').concat(str).join(' ');
},
removeClass: (node, str) => {
const arr = node.className.split(' ');
const i = arr.indexOf(str);
node.className = arr.slice(0, i).concat(arr.slice(i + 1)).join(' ');
}
};
// DOM.prototype.highlight = (evt) => {
// const { evtX, evtY } = DOM.getEventOffsetCoords(evt, DOM.containerBounds);
//
// const highlightDiv = document.createElement('div');
// highlightDiv.className = 'highlight';
// highlightDiv.style.left = `${evtX}px`;
// highlightDiv.style.top = `${evtY}px`;
//
// DOM.container.appendChild(highlightDiv);
// setTimeout(() => { DOM.container.removeChild(highlightDiv); }, 500);
// }
export default DOM;