2013-01-22 44 views
2

我有一個動畫,我試圖完成,應該類似於從下面出現的氣泡,然後點擊,展開顯示文本。如何創建一個更好的爆炸效果

電流效應由該位的代碼製成:

jQuery('.bubble1').on('click', function() { 
jQuery(this).stop(true,true).hide('explode', { pieces: 75 } , 1000, function() { 
    jQuery('.corpo-del-testo').show(); 
}); 
}); 

I've also made a jsFiddle to demonstrate the effect

我想有更好的爆發效果,但我找不到解決方案,任何人都有類似的問題,或知道如何實現像更現實的爆炸泡沫?就像一陣爆發。

在此先感謝。

+0

你需要更具體一點什麼 「好」 的意思。 – JJJ

+0

很不錯的工作..... – muthu

+0

@Juhana少一些「pixellated」 – Matteo

回答

10

這是我創建的另一個泡泡彈出效果。

http://jsfiddle.net/EkZBg

<div id="content"> 
    <div id="bubble"></div> 
    <div id="dummy_debris" class="debris" /> 
</div> 

<script> 

$(function(){ 
    // Document is ready 
    $("#bubble").on("click", function(e) { 
    pop(e.pageX, e.pageY, 13); 
    }); 
}); 

function r2d(x) { 
    return x/(Math.PI/180); 
    } 

    function d2r(x) { 
    return x * (Math.PI/180); 
    } 

    // Specify particle_count as 10 + Math.random()*10 to make things interesting! 
    function pop(start_x, start_y, particle_count) { 
    arr = []; 
    angle = 0; 
    particles = []; 
    offset_x = $("#dummy_debris").width()/2; 
    offset_y = $("#dummy_debris").height()/2; 

    for (i = 0; i < particle_count; i++) { 
     rad = d2r(angle); 
     x = Math.cos(rad)*(80+Math.random()*20); 
     y = Math.sin(rad)*(80+Math.random()*20); 
     arr.push([start_x + x, start_y + y]); 
     // You could use an IMG tag here instead to make the particles sprites 
     z = $('<div class="debris" />'); 
     z.css({ 
     "left": start_x - offset_x, 
     "top": start_y - offset_x 
     }).appendTo($("#content")); 
     particles.push(z); 
     angle += 360/particle_count; 
    } 

    $.each(particles, function(i, v){ 
     $(v).show(); 
     $(v).animate({ 
     top: arr[i][1], 
     left: arr[i][0], 
     width: 4, 
     height: 4, 
     opacity: 0 
     }, 600, function(){ 
     $(v).remove() 
     }); 
    }); 
    } 
</script> 

<style> 
/* Add browser prefixes as-needed. See CSS3please.com */ 
.debris { 
display: none; 
position: absolute; 
width: 28px; 
height: 28px; 
background-color: #ff00ff; 
opacity: 1.0; 
overflow: hidden; 
border-radius: 8px; 
} 

#bubble { 
    position:absolute; 
    background-color: #ff0000; 
    left:150px; 
    top:150px; 
    width:32px; 
    height:32px; 
    border-radius: 8px; 
    z-index: 9; 
} 
</style> 
+0

當使用大量碎片(> 100)時,它似乎表現不佳,並且在爆炸發生時應該刪除起始元素 – Matteo

+0

您沒有指定需要「超過100個」碎片。 Javascript不是一個高性能的圖形引擎。您可以使用CSS3動畫或使用硬件加速的轉場來提升性能。隱藏原始元素非常簡單。你似乎掌握了基本知識,所以我把它留給了你。將它添加到click處理程序中:$(this).hide(); – gooberverse

+0

我不能只隱藏()元素,結果不會很好。另外,100多個片段似乎是您的腳本實際需要的體驗效果 – Matteo