我正在尝试根据用户使用 jQuery.path 进行的多次点击来为特定的 HTML 元素设置动画。我遇到的问题是我不确定选择与所选元素相关的参数的最佳方法。
这是我当前的代码:
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 the amount of user clicks (looping)
}
});
理想情况下,我想要这条线......
$("#segment-"+segmentSelected).animate({path : new $.path.bezier(segment1Params)})
...选择正确的参数集。
我认为这可以通过数组来完成,但在语法上我不确定最好的方法。