CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 28th, 2004, 05:04 AM
ben9909 ben9909 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 6 ben9909 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 16 sec
Reputation Power: 0
CSS- Loops and Vars

Hello all,

I am trying to get a picture seperated into 24 pieces to appear.

I need to write the necessary javascript that will generate the complete image dynamically. To do this efficiently I need to store the source for each image in an array(s) and loop through the array(s) and produce the html to generate the complete image.

If someone would be kind enough to post some sample code to put me in the right direction, or what loop to use that would be great.

Kind Regards,
Ben

Reply With Quote
  #2  
Old April 28th, 2004, 07:20 AM
Dusk's Avatar
Dusk Dusk is offline
Twilight Thinking
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2003
Location: Oxford UK
Posts: 656 Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 21 m 15 sec
Reputation Power: 32
However you've got the images laid out onscreen (I'm guessing a table or divs) make sure you give each image an id, like:

<img src="whatever" id="image1" />

then, the easiest way to do this would be to call all your images somthing like: 1.gif, 2.gif 3.gif, etc.

the the js would look something like this:

Code:

for (i=1; i<24; i++)
{
   img = 'image' + i;
   src = 'yourpath' + i + '.gif';
   document.getElementById(img).src = src;
}


however, if you HAVE to use an array, it would look something like:

Code:

images = array('this1', 'that1', 'anuver1', 'this1too');

for (i=1; i<24; i++)
{
   img = 'image'+i;
   src = 'yourpath' + images[i] + '.gif';
   document.getElementById(img).src = src;
}


hope that helps
__________________
Cheers,
Dusk

My portfolio

Reply With Quote
  #3  
Old April 28th, 2004, 07:28 AM
Dusk's Avatar
Dusk Dusk is offline
Twilight Thinking
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2003
Location: Oxford UK
Posts: 656 Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level)Dusk User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 21 m 15 sec
Reputation Power: 32
Ah, just read your post again, and noticed that you need to generate the html too.

Try this:

Code:

images = array('this1', 'that1', 'anuver1', 'this1too');
c_image = "":

function write_img ()
{

   for (i=1; i<24; i++)
   {
      src = 'yourpath' + images[i] + '.gif';
      c_image += '<div id="?"><img src="' + src + '" /></div>";
   }

}


//then where you want the image to appear:

<script>document.write(c_image);</script>


hope that helps

Reply With Quote
  #4  
Old April 28th, 2004, 07:45 AM
ben9909 ben9909 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 6 ben9909 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 16 sec
Reputation Power: 0
Thanks for the Dusk, that put me in he right direction

cheers,

Ben

Reply With Quote
  #5  
Old April 28th, 2004, 08:37 AM
ben9909 ben9909 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 6 ben9909 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 16 sec
Reputation Power: 0
Hit another snag, I still cannot get the images to appear

Here is the code that I have used so far:

-------------------------------------------
<html>
<head>
<title>3755P - The Dollhouse</title>

<script type="javascript" language="text/javascript">

var newArray= theImages();
var theImages[1]="1.jpg";
var theImages[2]="2.jpg";
var theImages[3]="3.jpg";
var theImages[4]="4.jpg";

function write_img ()
{

for (i=1; i<24; i++)
{
src = 'yourpath' + images[i] + '.jpg';
c_image += '<div id="?"><img src="' + src + '" /></div>";
}

}
return;
</script>
</head>

<body bgcolor="#FFFFFF" link="#FF9933" alink="#F9933" vlink="#FF9933" background="">
<!--Begin Dynamic Table-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" background="">
<tr>
<td width="25%"><script>document.write('1.jpg');</script></td>
<td width="25%"><script>document.write('2.jpg');</script></td>
<td width="25%"><script>document.write('3.jpg');</script></td>
<td width="25%"><script>document.write('4.jpg');</script></td>
</tr>

</body>
</html>
-------------------------------------------

This is the code that I have used, I am new to this language so I apologise if the code seems completly wrong.
Any thoughts?

Regards,
Ben

Reply With Quote
  #6  
Old April 28th, 2004, 09:35 AM
bergner bergner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 144 bergner User rank is Private First Class (20 - 50 Reputation Level)bergner User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 48 m 6 sec
Reputation Power: 5
let me guess, you see 1.jpg, 2.jpg...

Throw away the 'yourpath' stuff. That was just a part of the previous example. Have write_img() take the filename as a parameter. For example:
Code:
function write_img(f, cls) {
  var html = '<img src="'+f+'" class="'+cls+'">';
  document.write(html);
}

Then use JavaScript to generate your table, e.g.:
Code:
<SCRIPT TYPE="text/javascript">
document.write('<table class="mytbl"><tr>');
for (var i = 0; i < theImages.length; i++) {
  document.write('<td class="mytd">' + write_img(theImages[i], 'myimg') + '</td>');
}
document.write('</tr></table>');
</SCRIPT>

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > CSS- Loops and Vars


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT