Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Animated Canvas as a background image of a website

Posted on 2014-03-12
9
Medium Priority
?
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 59

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
Stressed Out?

Watch some penguins on the livecam!

 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
The goal of this is to tech the user how to export photos out of Lightroom and the different options they have. Select which photos you want to export : Select where you want to export and with which options : Export :
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This videā€¦

704 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