简体   繁体   English

如何存储高度值数组并在另一个脚本中使用它们

[英]How to store an array of height values and use them in another script

I have a lot to learn so could really use some pointers: http://jsfiddle.net/David_Knowles/9kDC3/ 我有很多东西需要学习,所以可以使用一些指针: http//jsfiddle.net/David_Knowles/9kDC3/

QUESTION

  1. I am trying store iteratively the height values of bars in a bar chart. 我正在尝试迭代存储条形图中条形的高度值。
  2. Then i set the height of all to zero 然后我将所有的高度设置为零
  3. I then trigger an animation of the bars where I increase height towards the original values stored in array 然后我触发条形图的动画,我将高度增加到存储在数组中的原始值

Problem 问题

  1. It looks to me that the array is being overwritten instead of increasingly filled 在我看来,数组被覆盖而不是越来越多
  2. I don't know what the best way is to share the array values with the other script I later trigger 我不知道最好的方法是与我后来触发的其他脚本共享数组值

// //

$(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");
});
});

Updated! 更新!

Initialized origHeight outside of your function call, added parameter "i" to $($theBars).each function (passes the index to the each call), and set MyH: origHeight[i] . 在函数调用之外初始化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!");
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对多维数组值求和并将它们存储在另一个数组中 - Sum multidimensional array values and store them in another array 如何<span>从数组中</span>提取<span>元素值并将其存储到另一个数组中</span> - how to extract <span> element values from an array and store them into another array.Javascript Google Apps脚本返回数组值,并在javascript函数中使用它们 - Google Apps Script return array values and use them in a javascript function 如何通过类名获取元素值并将它们存储在jQuery中的数组中? - How to get elements values by class name and store them in an array in jQuery? 如何在(“输入”)上获取多个值并将它们存储在数组中 - How to get multiple values on("input") and store them in an array 如何使用jQuery检索值并将其存储在数组中 - How to retrieve values from json and store them in an array using jQuery 如何将listbox的值存储到数组中,然后使用它将其数据显示到另一个页面php中 - How to store the values of listbox into an array then use it to display its data into another page php 如何使用String.charCodeAt(); 一次获取并存储字符串中每个字母的字符代码值并进行存储? - How to use String.charCodeAt(); to get and store char code values of each letter of a string at once and store them? 如何在Json Array中获取值并分别使用它们 - How to get values in Json Array and use each of them separately 混淆如何将数组中的值与另一个变量一起使用 - Confused on how to use values in an array with another variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM