Last active
June 22, 2016 14:24
-
-
Save safhac/b9f8827ff729a07945df11d2a3786ca6 to your computer and use it in GitHub Desktop.
drag if over top border
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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