Solved

Animated Canvas as a background image of a website

Posted on 2014-03-12
9
320 Views
Last Modified: 2014-03-17
Hi,


Since I sligthly improve my knowledge in canvas thanks to EE (thanks!), I was wondering if it is possible to define a background canvas in my <body> like we can do with back-ground image.

The idea is to have an animated canvas that would run.

Of course I prefer to test my ideas before beginig to try to code.

So firstly my question is does some one knows if it is possible and would have an example of coding,please.

Great thanks.
David
0
Comment
Question by:DavidInLove
  • 4
  • 4
9 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 39923801
sure add this style.
body {
  background: url(myanimatedimage.gif) no-repeat 0 0;
}

Open in new window

0
 

Author Comment

by:DavidInLove
ID: 39924271
Thanks julian,
But here it is not an animated image
it is a canvas that I create
Dave
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39924479
David,

I think you have confused the issue slightly by specifically referring to "background-image". You want to use a canvas element and that is possible but I'm not sure what issues can arise with the content being displayed over it (like form fields etc). I have fiddled you a working example: http://jsfiddle.net/robert_schutt/7g5dj/

Note that I have included some generic code (by Paul Irish and others) to use a modern way to animate instead of using setInterval.
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39925406
Here is a different version that shows longer content scrolling over the canvas: http://jsfiddle.net/robert_schutt/7g5dj/2/

Note that this version does not use resize() to match the size of the canvas to the browser window. Resize has the disadvantage of clearing the canvas. But in this second version you have to be aware that there will be some zooming that can affect image quality on the canvas adversely (either stretching or compressing).
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Closing Comment

by:DavidInLove
ID: 39925918
Thanks Robert!

This works fine.

I will try to do something with colors nuance blue dark blue ...
Yes I agree it must be subbtle.
This gives me also an idea where I could see the canvas of EIffel Tower for example being drawn.

Since code is MIT it seems I just have to let included the comment with the author as you did?
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39925969
Yes, that's the general rule of thumb I keep with most public/open source licenses. Credit where credit's due.

Or, if update speed is not essential then you could also delete those 2 blocks of included code and use something 'old school' like:
setInterval(render, 1000); // call once per second

Open in new window

0
 

Author Comment

by:DavidInLove
ID: 39934063
Hi Robert,

Since you coded the first solution,
I opened  another question  how to get data pixel from the canvas to filter in a second canvas

Question
how to get the pixel data from a canvas filter it and create a 2 canvas.
how to get pixeldata from a canvas (open question EE Q_28390058
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39934364
I'll have a look tonight but hopefully some more experts will be able to help earlier. Isn't this what you already had working on your website?
0
 

Author Comment

by:DavidInLove
ID: 39934426
Robert,


On my website, it is what is working but I work with definition of Canvas
ouside of the function in the JQ (global).

I don't know why but on my local computer this does a bugg I believe it is because
of loading DOM and defining CANVAS.

(if I define the canvas in a document ready it is no more global and I can t use
the data of the firts canvas in the function creating the second canvas)

That is why I prefer to understand it really.

I want an image gives a canvas => you solved it with sprites.

Now I want I take some data of canvas existing from images and I mix them
to create art.


For this I need to be able to get the data of a canvas to filter it and input it in
a second canvas.

Thanks if you can help.


 David
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Use email signature images to promote corporate certifications and industry awards.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now