Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 25th, 2003, 07:07 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to edislasm
Default Inserting new Image but no replacing

Hi everyone!.

I want to know if there is a way to place an image in x,y coordinates with javascript. I can't use image replacing nor visibility in layers. What I like to do is to make a new Image() and then -I don't know how- place the image somewhere in the page in x,y coordinates as in a html layer.
 
Old July 27th, 2003, 04:02 PM
Registered User
 
Join Date: Jul 2003
Location: Budapest, , Hungary.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lillu
Default

Hi,

Yes, it's possible with Javascript. If I understand it right, you want to preload some images with the new Image() constructor then set some properties like top, left and z-index.

<html>
<head>
<script language="javascript">
function setImage()
{
document.getElementById('im').style.position = 'absolute';
document.getElementById('im').style.top = '200px';
document.getElementById('im').style.left= '200px';
document.getElementById('im').style.zIndex='1';
}
</script>
</head>
<body onload="setImage()">
<img id="im" src="im1.gif" border="0">

</body>
</html>

Using getElementById is just one way (IE6).
For more compatibility you can use:

document.images['image_name'].style or
document.all['image_id'].style

In my opinion setting these properties with JS is quite clumsy and longish. Why don't you use CSS instead and only manipulate values with javascript where absolutely necessary?

I'm not sure what you're trying to do but here's a small CSS that stacks four images on top of each other. Because there's only one property that changes (z-index) you take care of all the other styles in the style definition:

<html>
<head>
<style type="text/css">
#im
{
position: absolute;
left:150px;
top:50px;
}
</style>
</head>

<body>
<img id="im" src="im1.gif" style="z-index:1;" border="0">
<img id="im" src="im2.gif" style="z-index:2;" border="0">
<img id="im" src="im3.gif" style="z-index:3;" border="0">
<img id="im" src="im4.gif" style="z-index:4;" border="0">
</body>
</html>

HTH,

Lillu

The Purple Couch
http://www.geocities.com/lillamarta
 
Old July 27th, 2003, 11:53 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to edislasm
Default

What I'm trying to do is place my images over MSN logos in a hotmail message. HTML layers doesn't work because the Top variable is automatically changed. Javascript doesn't work because the tag <SCRIPT language="javascript"> is changed to <COMMENT language="javascript">.

I would like to find the way to do this. But I see that hotmail is very protected.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting an image in the header of a word documen Michael109 Access 3 April 4th, 2007 11:26 AM
inserting image data type object MAKO SQL Server 2005 1 September 8th, 2006 04:44 PM
HTML editor expert - inserting image itHighway Javascript How-To 0 May 9th, 2005 06:18 PM
inserting image into database vanjamier Classic ASP Databases 1 December 5th, 2004 10:57 PM
Keep inserting the same image to DB dcathers C# 2 August 31st, 2004 04:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.