How can you select a number of paramters from an array in JavaScript (jQuery.path) -


i trying animate specific html elements based on number of clicks user makes using jquery.path. problem i'm having i'm not sure of best way select parameters relative chosen element.

here current code:

    var segment1params = {        start: {           x: 414,           y: 121,           angle: 358.156,           length: 0.300         },         end: {           x: 114,           y: 121,           angle: 0.229,           length: 0.704         }       }      var segment2params = {        start: {           x: 494,           y: 104,           angle: 358.156,           length: 0.300         },         end: {           x: 114,           y: 121,           angle: 0.229,           length: 0.704         }       }      var segment3params = {        start: {           x: 420,           y: 306,           angle: 358.156,           length: 0.300         },         end: {           x: 114,           y: 121,           angle: 0.229,           length: 0.704         }       }      var segment4params = {        start: {           x: 514,           y: 389,           angle: 358.156,           length: 0.300         },         end: {           x: 114,           y: 121,           angle: 0.229,           length: 0.704         }       }       var segmentselected = 1;      $('body').click(function () {         segmentselected += 1; //the amount of user clicks         $("#segment-"+segmentselected).animate({path : new $.path.bezier(segment1params)})         if (segmentselected == 5) {             segmentselected = 1; //reset amount of user clicks (looping)         }     }); 

ideally want line...

$("#segment-"+segmentselected).animate({path : new $.path.bezier(segment1params)}) 

...to select correct set of parameters.

i thinking can done array syntactically unsure on best approach.

you can put segments 1 array , use function takes segment number argument , performs animation.

note segments[sid-1] - because in dom appears segments start 1: #segment-1, #segment-2 , on, array elements start default 0.

another thing initializing segmentselected 0: because variable supposed mean how many times user clicked on body element, , says "0 times" before clicks happen.

var segments = [{        start: {           x: 414,           y: 121,           angle: 358.156,           length: 0.300         },         end: {           x: 114,           y: 121,           angle: 0.229,           length: 0.704         }       },      {        start: {           x: 494,           y: 104,           angle: 358.156,           length: 0.300         },         end: {           x: 114,           y: 121,           angle: 0.229,           length: 0.704         }       } ... ];         var segmentselected = 0;         function animatesegment(sid)        {                   $("#segment-"+sid).animate({path : new $.path.bezier(segments[sid-1])});        }         $('body').click(function () {         segmentselected += 1; //the amount of user clicks         animatesegment(segmentselected);         if (segmentselected == 5) {             segmentselected = 0; //reset amount of user clicks (looping)         }     }); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -