我有很多需要学习的东西,所以可以使用一些指针:http://jsfiddle.net/David_Knowles/9kDC3/
问题
问题
//
$(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");
});
});
答案 0 :(得分: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!");
});
});