Created
June 13, 2015 19:04
-
-
Save ignacioazzi/8dadcae43f7ddf52f053 to your computer and use it in GitHub Desktop.
Dragging toggled by click_down
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
<p>Click and hold to start dragging. <br />Release to stop drag.</p> | |
<div class="variable"></div> | |
</div> | |
<div class="click"></div> | |
</div> | |
<div class="dragging"></div> | |
</div> | |
<div class="moved"></div> | |
</div> | |
<div class="element"></div> | |
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
var is_following = false; | |
$(document).click(function(e) { | |
is_following = !is_following; | |
$(".variable").text(is_following); | |
mouse_clickX = (e.pageX); | |
mouse_clickY = (e.pageY); | |
$(".click").text("First Click: " + mouse_clickX + " "+ mouse_clickY) | |
}); | |
$(document).mousemove(function(e) { | |
mouse_moveX = (e.pageX); | |
mouse_moveY = (e.pageY); | |
if (is_following) { | |
$(".element").css({"top":mouse_moveY, "left": mouse_moveX}) | |
} | |
$(".dragging").text("Moving: " + mouse_moveX + " "+ mouse_moveY) | |
}); | |
$(document).mousedown(function(e) { | |
is_following = !is_following; | |
$(".variable").text(is_following); | |
}); | |
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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
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
body{ | |
text-align: center; | |
font-size: 15px; | |
font-family: sans-serif; | |
padding: 100px; | |
} | |
p{ | |
font-size: 18px; | |
font-weight: bold; | |
margin-bottom: 3em; | |
} | |
div{ | |
} | |
.element{ | |
height: 30px; | |
width: 30px; | |
border-radius: 20px; | |
border:3px solid black; | |
} | |
.element{ | |
position: absolute; | |
top: 20px; | |
left: 20px; | |
} | |
body, html{ | |
position: relative; | |
cursor:none!important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment