Solved

Animated Canvas as a background image of a website

Posted on 2014-03-12
9
324 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 55

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The goal of the tutorial is to teach the user what exposure is and how to use the exposure slider. Analyze the photo that you want to edit, then adjust the exposure slider to your liking.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

840 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