javascript - Raphael transform object diagonally and infinite setIntervals -


i'm working on small animation user drags circle , circle returns starting point. figured out way have circle return starting point. problem hit 1 of sides of frame before returning. possible go straight (follow path of line drawn between shape , starting point).

the other problem setinterval doesn't want stop. if try pulling second time pull before release mouse. seems speed after every time. have tried using while loop timer results weren't good. fixable?

    var paper = raphael(0, 0, 320, 200);     //var path = paper.path("m10 10l40 40").attr({stoke:'#000000'});     //var patharray = path.attr("path");     var circle = paper.circle(50, 50, 20);     var newx;     var newy;     circle.attr("fill", "#f00");     circle.attr("stroke", "#fff");         var start = function () {         this.attr({cx: 50, cy: 50});         this.cx = this.attr("cx"),         this.cy = this.attr("cy");      },      move = function (dx, dy) {         var x = this.cx + dx,         y = this.cy + dy;         this.attr({cx: x, cy: y});      },       = function () {         setinterval(function () {     if(circle.attr('cx') > 50){         circle.attr({cx : (circle.attr('cx') - 1)});     } else if (circle.attr('cx') < 50){         circle.attr({cx : (circle.attr('cx') + 1)});     }       if(circle.attr('cy') > 50){         circle.attr({cy : (circle.attr('cy') - 1)});     } else if (circle.attr('cy') < 50){         circle.attr({cy : (circle.attr('cy') + 1)});     }     path.attr({path: patharray}); },2);  }; 

circle.drag(move, start, up);

here's jfiddle: http://jsfiddle.net/uznp2/

thanks alot :d

i modified "up" function 1 below

up = function () {   //starting x, y of circle go   var interval = 1000;   var startingpointx = 50;   var startingpointy = 50;   var centerx = this.getbbox().x + (this.attr("r")/2);   var centery = this.getbbox().y + (this.attr("r")/2);   var transx = (centerx - startingpointx) * -1;   var transy = (centery - startingpointy) * -1;   this.animate({transform: "...t"+transx+", "+transy}, interval); }; 

and "start" function follows:

var start = function () {   this.cx = this.attr("cx"),   this.cy = this.attr("cy"); } 

is behavior looking for? sorry if misunderstood question.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -