Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    1
    Thanked 0 Times in 0 Posts

    [SOLVED] Just need to add a code.

    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.

    Code:
    <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.
    Last edited by Eben; 12-20-2007 at 04:37 PM. Reason: [SOLVED]

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    Code:
    <!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>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thank you very much vwphillips, i'll try to learn the code


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •