...

View Full Version : [SOLVED] Just need to add a code.



Eben
12-20-2007, 03:08 AM
Hi guys, i have this code that auto resizes images using etElementsByTagName,
the code works fine however i want to add at the bottom of any image a div but i couldn't find how or where to put it in the code.
Any help will be appreciated.


<script language='JavaScript'>
window.onload = resizeimg;

function resizeimg()
{
if (document.getElementsByTagName)
{
for (i=0; i<document.getElementsByTagName('img').length; i++)
{ im = document.getElementsByTagName('img')[i];
width = im.width;
height = im.height;
if (im.width > 600)
{
im.style.width = '600px';
eval("pop" + String(i) + " = new Function(\"pop = window.open('" + im.src + " ','fullscale','width=400,height=400,scrollbars=1,resizable=1'); pop.focus();\")");
eval("im.onclick = pop" + String(i) + ";");
if (document.all) im.style.cursor = 'hand';
if (!document.all) im.style.cursor = 'pointer';
im.title = 'Click Here To See Image Full Size ['+width+' X '+height+']';
}
}
}

}

</script>

thanks.

vwphillips
12-20-2007, 11:47 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language='JavaScript'>
window.onload = resizeimg;

function resizeimg()
{
if (document.getElementsByTagName)
{
for (i=0; i<document.getElementsByTagName('img').length; i++)
{ im = document.getElementsByTagName('img')[i];
width = im.width;
height = im.height;
if (im.width > 600)
{
im.style.width = '600px';
im.onclick = function(){
pop = window.open(this.src,'fullscale','width=400,height=400,scrollbars=1,resizable=1');
pop.focus();
}
if (document.all) im.style.cursor = 'hand';
if (!document.all) im.style.cursor = 'pointer';
im.title = 'Click Here To See Image Full Size ['+width+' X '+height+']';
var par=zxcES('DIV',{position:'relative',left:zxcPos(im)[0]+100+'px',top:zxcPos(im)[1]+'px',width:im.width+'px',height:im.height+'px'},document.getElementsByTagName('BODY')[0]);
par.appendChild(im);
var txt=zxcES('DIV',{position:'absolute',left:'0px',top:im.height-40+'px',width:im.width+'px',height:'40px',textAlign:'center',border:'solid black 1px'},par,'Some Text');
}
}
}

}
function zxcES(zxcele,zxcstyle,zxcp,zxctxt){
if (typeof(zxcele)=='string'){ zxcele=document.createElement(zxcele); }
for (key in zxcstyle){ zxcele.style[key]=zxcstyle[key]; }
if (zxcp){ zxcp.appendChild(zxcele); }
if (zxctxt){ zxcele.appendChild(document.createTextNode(zxctxt)); }
return zxcele;
}
function zxcPos(zxcobj){
zxclft=zxcobj.offsetLeft;
zxctop=zxcobj.offsetTop;
while(zxcobj.offsetParent!=null){
zxcpar=zxcobj.offsetParent;
zxclft+=zxcpar.offsetLeft;
zxctop+=zxcpar.offsetTop;
zxcobj=zxcpar;
}
return [zxclft,zxctop];
}

</script>

</head>

<body>
<br />
<br />
<img src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" width="800" />
</form>
</body>

</html>

Eben
12-20-2007, 04:35 PM
thank you very much vwphillips, i'll try to learn the code ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum