0

I have lines which are drawn with the Raphaeljs library and each start and end coordinates of the lines drawn are saved in an array and are used for the animation so that the animation moves from the start of the line to the end of the line.

This is working for only one index of the array I specify.

These are the codes for it:

$("#menu_button3").click(function() {
  var start = $("#sldr");
  if (!start.hasClass('started')) {
    start.addClass('started');
    $('#sldr').css({
      "left": startx[1], //line at index 1 in the array
      "top": 160 + starty[1],
      "visibility": "visible"
    });

    $("#sldr").css({
      'display': 'block',
      'transition': 'none',
      'width': '50px'
    }).animate({
        left: endx[1] - 15,
        top: 160 + endy[1]
      }, 2000,
      function() {
        node.attr("stroke", "green");
        start.removeClass('started');
        $('#sldr').css('visibility', 'hidden');
      })
  };
});

I tried using a for loop to iterate through each line but the animation still plays on only the first line.

Any solution for this please?

Rajesh
  • 24,354
  • 5
  • 48
  • 79
Manisha Singh Sanoo
  • 919
  • 1
  • 13
  • 42
  • I totally don't understand what are you trying to do and what your code was supposed to do, as it doesn't seem to have anything to do with your description :D you are simply animating some one element with given id after clicking a button... what does it have to do with your problem? – Flash Thunder Jan 23 '16 at 13:13
  • I posted only the codes for the animation as the coordinates of the lines drawn are already being saved to the array. startx, starty, endx and endy specify the arrays containing the coordinates. I use these coordinates to specify the direction that the image will be moving. I want to get the image to move on each line. – Manisha Singh Sanoo Jan 23 '16 at 13:15
  • maybe it helps you [.promise()](https://api.jquery.com/promise/) – kpucha Jan 23 '16 at 13:18
  • Nope not really. I need to find a way to make the image travel on each line. – Manisha Singh Sanoo Jan 23 '16 at 13:27
  • post example on jsfiddle ;-) – Flash Thunder Jan 23 '16 at 14:01

0 Answers0