Skip to content

Instantly share code, notes, and snippets.

@safhac
Last active June 22, 2016 14:24
Show Gist options
  • Save safhac/b9f8827ff729a07945df11d2a3786ca6 to your computer and use it in GitHub Desktop.
Save safhac/b9f8827ff729a07945df11d2a3786ca6 to your computer and use it in GitHub Desktop.
drag if over top border
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
margin: 0 auto;
text-align: center;
}
.container {
width: 100%;
height: 100%;
display: block;
}
#drag-if {
display: inline-block;
width:300px;
height: 200px;
border: solid thin lightgray;
border-top: solid 100px black;
}
</style>
<script src="script.js" type="text/javascript"></script>
</head>
<body>
<div class="container">
<div id="drag-if" draggable="false" onmouseover="setDraggable()" onmouseout="setNotDraggable()"></div>
</div>
</body>
</html>
function setDraggable() {
var elem = document.getElementById('drag-if');
var topBorder = parseInt(getComputedStyle(document.getElementById('drag-if'),null).getPropertyValue('border-top-width'));
if(event.clientY < topBorder) {
elem.setAttribute('draggable', true);
}
else {
elem.setAttribute('draggable', false);
}
}
function setNotDraggable() {
var elem = document.getElementById('drag-if');
elem.setAttribute('draggable', false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment