What i exactly want ?
make element clickable that is behind movable div.
Here is what i have tried for achieve that but its not working. And i did not found any other solution for this. This will be great help for me.
add style "pointer-events: none;" but after applying this style then that div is no drag-able.
Here is my code :
Red Div is movable but not clickable and Green Div is clickable but not movable.
function make_movable(id) {
var movable_div = document.getElementById(id);
movable_div.onmousedown = dragMouseDown;
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
movable_div.style.top = (movable_div.offsetTop - pos2) + "px";
movable_div.style.left = (movable_div.offsetLeft - pos1) + "px";
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
}
make_movable("movable_div1");
make_movable("movable_div2");
#movable_div1 {
cursor: move;
background: green;
width: 100px;
height: 100px;
position: absolute;
pointer-events: none;
opacity: 0.5;
}
#movable_div2 {
cursor: move;
background: red;
width: 100px;
height: 100px;
position: absolute;
opacity: 0.5;
/*pointer-events: none;*/
}
button {
width: 100px;
padding: 10px;
margin: 10px;
}
<button onClick="alert('Just pressed button 1');">BUTTON 1</button>
<button onClick="alert('Just pressed button 2');">BUTTON 2</button>
<button onClick="alert('Just pressed button 3');">BUTTON 3</button>
<button onClick="alert('Just pressed button 4');">BUTTON 4</button>
<button onClick="alert('Just pressed button 5');">BUTTON 5</button>
<button onClick="alert('Just pressed button 6');">BUTTON 6</button>
<button onClick="alert('Just pressed button 7');">BUTTON 7</button>
<button onClick="alert('Just pressed button 8');">BUTTON 8</button>
<button onClick="alert('Just pressed button 9');">BUTTON 9</button>
<button onClick="alert('Just pressed button 10');">BUTTON 10</button>
<div id="movable_div1" style="top: 40px; left: 40px;"> </div>
<div id="movable_div2" style="top: 160px; left: 40px;"> </div>