javascript - drag constraints in raphael.js and zoom -
i've had no problem getting basic zoom/pan effect raphael.js 2.0 using pan :
set = ( // set of elements, contained in rectangle) var start = function () { set.obb = set.getbbox(); }, move = function (dx, dy) { var bb = set.getbbox(); set.translate(set.obb.x - bb.x + dx, set.obb.y - bb.y + dy); }, = function() { // stuff }; set.drag(move, start, up); and zoom :
//before paper.setviewbox(0,0, 500,500, false); //after paper.setviewbox(0,0, 200, 200, false); but i'm having 2 big problems this. raphael-created svg object , not image...
- first, panning after zoom not 'smooth' : drag little , rectangle moves lot. movement gets worse farther go along. can scale drag somehow when have zoomed?
- second, how arrange panning zoomed rectangle doesn't let me move out of viewport? in jquery constraint, , i've tried playing set.translate function above include constraints i'm getting nowhere...
any advice appreciated, or else library exists doing in raphael.js? looked @ raphael-spz doesn't seem address either of problems above.
what i'd http://dannyvankooten.com/demo/draggable-image-map-with-zoom/ raphael. he's using jquery ui draggable... can't seem work in raphael.
thanks!
because have scaled viewbox might need scale drag values well, fro calculating bounds can compare against viewport, like,
move = function (dx, dy) { var bb = set.getbbox(), //move relative viewport scale x = dx/scale, y = dy/scale, //lower bounds xf = math.max(0, set.obb.x - bb.x + x), yf = math.max(0, set.obb.y - bb.y + y); //upper bounds xf = math.min(viewboxwidth, xf + bb.width) - bb.width; yf = math.min(viewboxheight, yf + bb.height) - bb.height; set.translate(xf, yf); } scale being factor viewbox different relative paper. ie(200/500)
Comments
Post a Comment