How can I change data-src attribut of a canvas in jquery
Hi,
In a previous post I've learned how to load a canvas from png.
It is great but now I feel not very pride because I have a technical problem I cannot solve.
I would like to load the data of different png one after one another.
My idea is to do a setinterval just specifying the data-src before execute for different images.
The problem is I don't find how to change data-src of canvas with JQUERY.
Here is my code.
Can some one just tell me where and what I must include to load for example testbis.png?
Thanks!
- <!DOCTYPE html>
- <html>
- <head>
- <title>ANIMATION with timer: a solution very difficult to apply</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <script src="http://code.jquery.com/jquery-2.1.0.js"></script>
- </script>
- </head>
- <body>
- <canvas id="myCanvas_IN" width="448" height="448" data-src="http://www.thecacaocafe.com/img/test.png">
- </canvas>
- <br>
- <script>
- $(function() {
-
- $("canvas[data-src]").each(function(){
- var img = new Image,
- canvas = this
- img.onload = function(){
- canvas.getContext("2d").drawImage(img, 0, 0);
- // at this point you have a loaded canvas, and can start playing with it.
- contextin = canvas.getContext("2d");
- imgdin = contextin.getImageData(0, 0, 448, 448);
- pixin = imgdin.data;
-
-
-
- for (var i=0;i<pixin.length;i++)
- {
- pixin[i*4 ] = (pixin[i*4 ] < 125)?pixin[i*4 ]*2:pixin[i*4 ];
- pixin[i*4 +1 ] = pixin[i*4 +1 ]/2;
- pixin[i*4 +2 ] = pixin[i*4 +2 ]/2;
- pixin[i*4 +3 ] = 255;
- }
-
- contextin.putImageData(imgdin, 0, 0);
-
-
-
-
-
-
- }
- img.src=$(canvas).data("src")
- })
- });
- </script>
- </body>
- </html>
David ( @webtecgeek www.thecacaocafe.com )