0

我有很多东西要学,所以真的可以使用一些指针:http: //jsfiddle.net/David_Knowles/9kDC3/

问题

  1. 我正在尝试在条形图中迭代地存储条形的高度值。
  2. 然后我将所有的高度设置为零
  3. 然后我触发条形的动画,在其中我将高度增加到存储在数组中的原始值

问题

  1. 在我看来,数组正在被覆盖而不是越来越多
  2. 我不知道最好的方法是与我稍后触发的其他脚本共享数组值

//

$(function(){
// get the height of all the bars
var $theBars = $("#v-bars").children();
var BarsHeight = $theBars.each(function(index, element ) {
    var origHeight = [];
    origHeight.push($(this).attr("height"));
    console.log (origHeight);
});

//
$("#svg-skills-expertise").click(function() {
    $($theBars).each(function(){
        $(this).css("MyH",$(this).attr("height")).animate(
        {
            MyH:400 // this value needs to be the array values so how 
        },
        {
            step:function(v1){
                $(this).attr("height",v1)
            }
        })
    })
    console.log ("Yeap the clicked it! callback");
});
});
4

1 回答 1

2

更新!

在函数调用之外初始化origHeight ,将参数“i”添加到$($theBars).each函数(将索引传递给每个调用),并设置MyH: origHeight[i]

/* SVG ARRAY \\\\\\\\\ */

var origHeight = [];
$(function(){
    var $theBars = $("#v-bars").children();
    var BarsHeight = $theBars.each(function(index, element ) {
        origHeight.push($(this).attr("height"));
        console.log (origHeight);
    });


    $("#svg-skills-expertise").click(function() {
        $($theBars).each(function(i){
            $(this).css("MyH",$(this).attr("height")).animate(
            {
                MyH:origHeight[i]
            },
            {
                step:function(v1){
                    $(this).attr("height",v1)
                }
            })
        })
        console.log ("Yeap clicked it!");
    });
});
于 2013-05-20T19:30:10.447 回答