 |
 |
Dumb Javascript Question 2
|
 |
|
 |
|
Mac Elite
Join Date: Apr 2001
Location: Frickersville
Status:
Offline
|
|
i have a blog on blogspot where i would like to post a lot of images. however, the images just trail down the page one after another. i'd like to implement some kind of image viewer. here is some javascript i found:
Code:
<script>
function changeImage(filename)
{
document.mainimage.src = filename;
}
</script>
<p align="center">
<a href="javascript:changeImage('image1.jpg')">Image 1</a>
<a href="javascript:changeImage('image2.jpg')">Image 2</a>
</p>
so, that's cool. but, if i post pictures for another day (i.e. another instance of the p text), only the last one on the page will update. is there some way to implement another variable in the changeImage javascript so that it will know which p to update? also, i'd like to add comment text under the pics too. how can i have the script update some text below the image as well?
as anyone could probably tell, i'm a total newbie at this stuff, so thanks for any help.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2005
Location: Mpls, MN
Status:
Offline
|
|
In order for you to use this with multiple images you are going to have to add an id attribute to every main image you are adding and pass that into the function.
Here's some sudo blog code.
Code:
<p>Blog Entry 1</p>
<img src="image.jpg" id="image_1" />
<p align="center">
<a href="javascript:changeImage('image1.jpg', 'image_1')">Image 1</a>
<a href="javascript:changeImage('image2.jpg', 'image_1')">Image 2</a>
</p>
<p>Blog Entry 2</p>
<img src="image.jpg" id="image_2" />
<p align="center">
<a href="javascript:changeImage('image1.jpg', 'image_2')">Image 1</a>
<a href="javascript:changeImage('image2.jpg', 'image_2')">Image 2</a>
</p>
Here's the function code.
Code:
<script>
function changeImage(filename, id)
{
var img = document.getElementById(id);
img.src = filename;
}
</script>
I'm not sure if you can add the ids using blogspot. Let me know how it works.
|

Thus, creating the most ginormous can of whoop ass the world as ever seen.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Apr 2001
Location: Frickersville
Status:
Offline
|
|
omg, you sir a a ****ing genius! i just implemented the changes, & they worked! thank you so much.
i have another question. could i add a line of text below the image area, then have it change as different images are clicked. in effect, i want to add updating captions. maybe add another tag to the links that would be passed to the img?
also, could i add some code to make "next" and "previous" links instead of having a ton of links?
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|