Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript/CSS: can a .js graphic be used as CSS background graphic?

Status
Not open for further replies.

shipsahoy

Programmer
Jun 27, 2006
4
US
Hello.

I have a routine that is stored in a .js file that displays a graphic upon loading.

Is it possible to integrate it with CSS to make it a background image? If so, how?

Thanks in advance.
 
You can try:
Code:
document.body.style.background = 'url(imagenamehere.jpg)';

Lee
 
Thanks for your reply.

The situation is that I am using a .js that is served to me to use on my site. Part of that routine displays an image. I just want that .js snippet (includes <script> tags) to load the script (image) into the background of a table cell.

I ultimately want to add more to the table cell as a partial overlay, e.g. color, or create a slightly-modified graphic to immediately switch with the original once loaded. I want it to work in all browsers. I am calling the script in a PHP file.

Is there an 'onload' command or other way (CSS, etc.) of doing this? Also, is there a way to move the .js outside of the <script> tags?

Thanks.
 
You're going to have so show some of your code to give a better idea of what you're working with. Show the real code, too, not something you put together as an example.

Lee
 
Thanks for your reply.

I'm trying out the code for someone so I can't post the exact code here, but what I can say is that the link to the graphic is contained inside of the .js file. This graphic is to be displayed on the web page upon loading the .js file.

I have a rectangle.jpg that I want to place 'on top' (overlay) of the graphic at a particular corner of the graphic from the .js file.

Maybe it's not the 'background' I need to place the graphic contained in the .js file. Either way, it is a graphic contained in a javascript file that I want to sit behind the small rectangle.

Take a look at this example:
The lightbulb would be the rectangle.jpg and the text would be the results of loading the .js file.

Hope this is clear. I do appreciate your help.

Thanks in advance.
 
Sorry, without the code you're working with, it makes it a bit hard to answer any of your questions.

If you're 'drawing' a picture using javascript graphics techniques, then no, you won't be able to use it in any CSS.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top