Solved

Animated Canvas as a background image of a website

Posted on 2014-03-12
9
327 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 57

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
Technology Partners: 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!

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The goal of the tutorial is to teach the user how to remove a natural vignette your photos and how to add vignette to your photos.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

739 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