javascript - Making an element draggable without jquery ui? -


i'm trying build image cropper similar twitters - http://jsfiddle.net/yarkr/1/. i'm stuck on ability drag image. best way without resorting jquery ui?

<div class="canvas">     <span class="window"></span>     <img src="http://www.dailystab.com/blog/wp-content/uploads/2009/03/katy-perry-esquire-4.jpg" class="draggable" /> </div> 

i want able move drag image around inside .canvas div.

something work: jsfiddle

var thedraggable = null;  $(document).ready(function () {      $('.draggable').on({         mousedown: function () { thedraggable = $(this); },         mouseup: function () { thedraggable = null; }     });      $(document).mousemove(function (e) {          if (thedraggable) {              thedraggable.css({'top': e.pagey, 'left': e.pagex});         }     }); }); 

and css add this: .draggable { position:absolute; }

you rewrite , add form of easing on repositioning, change cursor or add more precise starting point based on initial click happened on picture overall, should started.


Comments

Popular posts from this blog

php - URL redirection after form submitted without inherited params -

c# - ReportViewer control - axd url -

c# - must be a non-abstract type with a public parameterless constructor in redis -