Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 09-15-2005, 04:37 PM
  #1
webgal20
Swordman (Level 9)
 
webgal20's Avatar
 
Join Date: Apr 2005
Location: Chicago, IL
Posts: 87
iTrader: (0)
webgal20 is on a distinguished road
Exclamation how to center an image using javascript

Hey everyone....I have a question. I was wondering if anyone knew how to center an image using javascript code. Below is what i have for the code. These functions are coded to click on thumbnails to see the enlargement picture of how i have it set up on my page. I would like to center 'Tabernacleverticalslide.jpg' & 'Tabernaclebigg.jpg' please feel free to reply if anyone know how to do this. Thanks

webgal20



<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
function canManipulateImages() {
if (document.images)
return true;
else
return false;
}
function loadPosterImage(imageURL) {
if (gImageCapableBrowser) {
document.imagePoster.src = imageURL;
if(imageURL=='images/Tabernacleverticalslide.jpg')
{
document.imagePoster.width=123;
document.imagePoster.height=409;
}
else if(imageURL=='images/Tabernaclebigg.jpg')
{
document.imagePoster.width=225;
document.imagePoster.height=363;
}
else
{
document.imagePoster.width=312;
document.imagePoster.height=242;
}
return false;
}
else {
return true;
}
}

gImageCapableBrowser = canManipulateImages();
// -->
</SCRIPT>
webgal20 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-15-2005, 05:16 PM
  #2
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 7,919
iTrader: (0)
coothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to behold
Hi there webgal20,

have a look at this example

Here is the code...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>thumbnail image to div background-image</title>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>

<base href="http://coothead.homestead.com/files/"/>

<style type="text/css">
/*<![CDATA[*/
html,body {
     margin:0px;
     padding:0px;
     height:100%;
     background-image:url('bodyBg.jpg');
 }
#links {
     position:absolute;
     top:20px;
     left:20px;
     width:70px;
     padding-top:4px;
     border:solid 1px #000;
     background-color:#333354;
}
 #links img {
     display:block;
     width:60px;
     height:60px;
     border:solid 1px #000;
     margin:0px 4px 4px 4px;
}
#display {
     position:absolute;
     border-top:solid 6px #333354;
     border-right:solid 6px #cecee0;
     border-bottom:solid 6px #cecee0;
     border-left:solid 6px #333354;
     display:none;  
 }
#close {
     width:75px;
     background-color:#333354;
     font-family:verdana,sans-serif;
     color:#fff;
     font-size:10px;
     text-align:center;
     margin:5px auto;
     padding:3px;
     cursor:pointer;

}
/*//]]>*/
</style>

<script type="text/javascript">
//<![CDATA[
 
   var preloads=[];
function preload(){
      for(var i = 0; i < arguments.length; i ++) {
           preloads[preloads.length] = new Image();
           preloads[preloads.length - 1].src = arguments[i];

  }
}
function showImage(w,h,i) {
  var image=preloads[i].src;
  var db=document.body;
  var obj=document.getElementById("display").style;
        obj.width=w+"px";
        obj.height=h+"px"
        obj.top=(db.offsetHeight-h)/2+"px";
        obj.left=(db.offsetWidth-w)/2+"px";
        obj.backgroundImage="url("+image+")";
        obj.display="block";

document.getElementById("close").onclick=function(){
        obj.display="none";
  }
 }
preload('dog.jpg','banana.jpg','aaa.jpg','ten_quid.JPG','apple.jpg','girl.jpg','clouds.jpg','grap.JPG');
//]]>
</script>

</head>
<body>

<div id="display">
<p id="close">
click to close
</p>
</div>

<div id="links">
<a href="dog.jpg" onclick="showImage(400,432,0);return false"><img src="dog.jpg"  alt=""/></a>
<a href="banana.jpg" onclick="showImage(360,280,1);return false"><img src="banana.jpg"  alt=""/></a>
<a href="aaa.jpg" onclick="showImage(200,200,2);return false"><img src="aaa.jpg"   alt=""/></a>
<a href="ten_quid.JPG" onclick="showImage(445,238,3);return false"><img src="ten_quid.JPG"  alt=""/></a>
<a href="apple.jpg" onclick="showImage(360,280,4);return false"><img src="apple.jpg"  alt=""/></a>
<a href="girl.jpg" onclick="showImage(347,201,5);return false"><img src="girl.jpg"  alt=""/></a>
<a href="clouds.jpg" onclick="showImage(640,400,6);return false"><img src="clouds.jpg"  alt=""/></a>
<a href="grap.JPG" onclick="showImage(740,514,7);return false"><img src="grap.JPG"  alt=""/></a>
</div>

</body>
</html>
__________________
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-29-2005, 07:17 AM
  #3
kewa
Novice (Level 1)
 
Join Date: Sep 2005
Posts: 4
iTrader: (0)
kewa is an unknown quantity at this point
Hi Coothead

I am really new to this. I was intending to try and link thumbnails to open in new pop up windows but saw your example above and thought that was even better.

If I try to use your code as it is I get all your thumbnails as large images and if I click on them they open in a new window.

As I said I'm really new to this so must be doing something stupid so please accept my apologies in advance.

Would it have anything to do with me using MS Word as my HTML editor?

I'd really appreciate some help.

Thanks

Kewa
kewa is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-29-2005, 07:56 AM
  #4
birdbrain
Paladin (Level 15)
 
Join Date: Sep 2005
Location: I have a bijou perch
Posts: 314
iTrader: (0)
birdbrain is an unknown quantity at this point
Hi kewa,

and welcome to htmlforums.
Quote:
Would it have anything to do with me using MS Word as my HTML editor?
I would suggest that you use 'Notepad' instead.
Quote:

If I try to use your code as it is I get all your thumbnails as large images
and if I click on them they open in a new window.
If you supply a link to your site and/or the code that is giving you problems,
then the members here will be better able to help you, I am certain.
birdbrain is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 09:53 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.