Solved

Animated Canvas as a background image of a website

Posted on 2014-03-12
9
322 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 52

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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 :
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

867 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

26 Experts available now in Live!

Get 1:1 Help Now