Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
I am trying to code a web version of iphone app wobble(http://www.chillifresh.com/) in css and javascript.

I tried HTML5 canvas, but had very bad performance issue.

Now trying css keyframes and transitions, but no improvement in performance. Because I have to load same image more than 200 times at a time to give such bouncy effects by manipulating each pixel.

Is there any other better way to do this.
Posted
Comments
Sergey Alexandrovich Kryukov 9-Sep-13 10:55am    
That is certainly a problem. Did you think about having a server-side processing?
—SA
praveena0989@gmail.com 9-Sep-13 11:06am    
I want to do this only using client side technologies..-PSP
enhzflep 9-Sep-13 13:51pm    
Not really sure what the reason is to "load same image more than 200 times at a time". You simply load the target image once. You then compute copies of the image, 1 for each frame.

I'd be inclined to investigate WebGL if you feel that the canvas isn't up to the task. Don't think that using canvas.setPixel, or whatever the built-in function is called, will be any-good either!

You'll need to write to the memory buffer that the canvas has, directly if you want any decent sort of speed.
praveena0989@gmail.com 10-Sep-13 5:47am    
In canvas I tried using drawImage.. drawing each pixel to he canvas. But it was facing horrible
performance issue..(I am writing code for mobile browsers).

1 solution

HTML CODE:
XML
<table>
<tr>
    <td><div id="bouncy1">Click here to bounce. Direction: Up</div></td>
    <td><div id="bouncy2">Click here to bounce. Direction: Left</div></td>
</tr>
<tr>
    <td><div id="bouncy3">Click here to bounce. Direction: Right</div></td>
    <td><div id="bouncy4">Click here to bounce. Direction: Down</div></td>
</tr>
</table>
<br/>
<input id="bounceAll" type="button" value="Click to Bounce All!"/>


The Stylesheet CSS Code:
CSS
div {
    padding:5px;
    width:150px;
    height:100px;
    text-align:center;
}
#bouncy1 {
    background-color:#FFEE88;
}
#bouncy2 {
    background-color:#EE88FF;
}
#bouncy3 {
    background-color:#EE8888;
}
#bouncy4 {
    background-color:#88EEFF;
}


The jQuery/JavaScript Code
XML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>


Also copy following code in your HTML to give final bounce effect.
$(function(){

//Add bounce effect on Click of the DIV
$('#bouncy1').click(function () {
$(this).effect("bounce", { times:5 }, 300);
});

$('#bouncy2').click(function () {
$(this).effect("bounce", { direction:'left', times:5 }, 300);
});

$('#bouncy3').click(function () {
$(this).effect("bounce", { direction:'right', times:5 }, 300);
});

$('#bouncy4').click(function () {
$(this).effect("bounce", { direction:'down', times:5 }, 300);
});

//Bounce all DIVs on click of button
$("#bounceAll").click(function(){
$("div").click();
});
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900