0
我新手拉斐爾,我想拉斐爾動畫爲多個div。目前我有單人div的動畫。但我無法爲多個div做衝突。拉斐爾動畫爲多個div
以下是代碼
http://tympanus.net/codrops/2011/04/22/animated-skills-diagram/
HTML
<div class="diagram"></div>
<div class="get">
<div class="arc">
<span class="text">JavaScript</span>
<input type="hidden" class="percent" value="95" />
<input type="hidden" class="color" value="#97BE0D" />
</div>
<div class="arc">
<span class="text">CSS3</span>
<input type="hidden" class="percent" value="90" />
<input type="hidden" class="color" value="#D84F5F" />
</div>
</div>
<div class="diagram"></div>
<div class="get">
<div class="arc">
<span class="text">JavaScript</span>
<input type="hidden" class="percent" value="95" />
<input type="hidden" class="color" value="#97BE0D" />
</div>
<div class="arc">
<span class="text">CSS3</span>
<input type="hidden" class="percent" value="90" />
<input type="hidden" class="color" value="#D84F5F" />
</div>
</div>
等等...
JAVASCRIPT
var o = {
init: function(){
this.diagram();
},
random: function(l, u){
return Math.floor((Math.random()*(u-l+1))+l);
},
diagram: function(){
var r = Raphael($('.diagram'),600,600), //need effects for all the div
rad = 3,
defaultText = 'Skills',
speed = 250;
r.circle(300, 300, 20).attr({ stroke: 'none', fill: '#193340' });
var title = r.text(300, 300, defaultText).attr({
font: '12px Arial',
fill: '#fff'
}).toFront();
r.customAttributes.arc = function(value, color, rad){
var v = 3.6*value,
alpha = v == 360 ? 359.99 : v,
random = o.random(91, 240),
a = (random-alpha) * Math.PI/180,
b = random * Math.PI/180,
sx = 300 + rad * Math.cos(b),
sy = 300 - rad * Math.sin(b),
x = 300 + rad * Math.cos(a),
y = 300 - rad * Math.sin(a),
path = [['M', sx, sy], ['A', rad, rad, 0, +(alpha > 180), 1, x, y]];
return { path: path, stroke: color }
}
$('.get').find('.arc').each(function(i){
var t = $(this),
color = t.find('.color').val(),
value = t.find('.percent').val(),
text = t.find('.text').text();
rad += 17;
var z = r.path().attr({ arc: [value, color, rad], 'stroke-width': 12 });
z.mouseover(function(){
this.animate({ 'stroke-width': 20, opacity: .75 }, 1000, 'elastic');
if(Raphael.type != 'VML') //solves IE problem
this.toFront();
title.stop().animate({ opacity: 0 }, speed, '>', function(){
this.attr({ text: text + '\n' + value + '%' }).animate({ opacity: 1 }, speed, '<');
});
}).mouseout(function(){
this.stop().animate({ 'stroke-width': 12, opacity: 1 }, speed*4, 'elastic');
title.stop().animate({ opacity: 0 }, speed, '>', function(){
title.attr({ text: defaultText }).animate({ opacity: 1 }, speed, '<');
});
});
});
}
}
$(function(){ o.init(); });
http://tympanus.net/codrops/2011/04/22/animated-skills-diagram/
我使用arraylist並生成多個div,我如何執行此代碼爲每個div。請幫助我。謝謝 – Akshay
它看起來不像你使用arrayList。我使用了上面引用的代碼,然後在多個地方引用r.circle等,而後面的代碼如「$('。get')。find('。arc')。each(」is being used(each means它會通過每一個)爲什麼不簡單地拿他的代碼激動地,給每個div像他一樣的唯一的id,並改變o.init爲id接收一個字符串,將它傳遞到圖函數並調用o.init (「圖」); o.init(「圖2」);等等,如果你不明白這個代碼會更容易 –
再看看它,我的最後一條評論將不會工作,因爲代碼使用其他班級/編號來查找元素,這意味着所有內容都必須是獨一無二的。本網站向人們提出想法和小型解決方案,不是要求人們爲你做點什麼,我沒有時間去調查如果你不瞭解這些技術,那就不要使用它們或者花時間去學習它們,你需要用類「圖表」來循環每個div,並獲得每個div通過使用像「div.getElementsByTagName(標記名)」這是一個標準的DOM方法。 as ... –