Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Javascript rolling image
Old 01-04-2009, 11:36 PM Javascript rolling image
ADeacon's Avatar
Experienced Talker

Posts: 32
Name: Andrew
Location: Texas
Trades: 0
Hello everyone,

I am trying to get an arrow picture to correspond with a link. When a person clicks the link, the arrow points down to the content. The problem I am having is getting the arrow to return to normal when the user clicks the link again. Below is the link to the page in question. Thanks in advance for any advice you all might have.

http://drawninwardmedia.com/firstint...2/careers.html
ADeacon is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-05-2009, 03:04 AM Re: Javascript rolling image
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
You could change the function change1 to first check what image is currently inside the img tag.
Then thereby choose what new image should go in the img tag.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 10:50 AM Re: Javascript rolling image
ADeacon's Avatar
Experienced Talker

Posts: 32
Name: Andrew
Location: Texas
Trades: 0
What would be the best way to go about that? I am a Javascript novice.
ADeacon is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 11:07 AM Re: Javascript rolling image
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
document[imgName].src acts as a variable, and therefore you can check it's value with an if-statement.

Code:
if(document[imgName].src==img1){
document[imgName].src = img2;
}else{
document[imgName]src. = img1;
}
This code doesn't actually work but it's just to show you the idea.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 12:03 PM Re: Javascript rolling image
ADeacon's Avatar
Experienced Talker

Posts: 32
Name: Andrew
Location: Texas
Trades: 0
So I've altered my code, just for the first arrow to this:

- - - -

function change1(picName,imgName)
{
if(document[imgName].src==image_off){
document[imgName].src = image2;
}else{
document[imgName]src. = image_off;
}

- - - -

It still points down when I click on the link, but doesn't come back up. Thanks for the help so far.
ADeacon is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 12:10 PM Re: Javascript rolling image
ADeacon's Avatar
Experienced Talker

Posts: 32
Name: Andrew
Location: Texas
Trades: 0
Strike that. I was trying to replace the Change1 statement with the IF statement you gave me and it broke the script. What I was thinking might be this:

function change1(picName,imgName)
{
if (document.images)
{
imgOn=eval(imgName + ".src");
document[picName].src= imgOn;
}
if(document[imgName].src==image_off){
document[imgName].src = image2;
}else{
document[imgName]src. = image_off;
}
}
ADeacon is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 12:31 PM Re: Javascript rolling image
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
As I said, if you had read closely, the code I provided wasn't working code.
I simply made a simple example to show you how it should look like.

You should store the locations of the images in your javascript, maybe as an array.
Then make the change function get the current image, and make it be the other.

Code:
function change1(picName)
{
if (document.images)
{
if(document[picName].src == images[0]){
document[picName].src = images[1];
}else{
document[picName].src = images[0];
}
}
What you need to do to make this code work is store the locations for the image in the array images.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Javascript rolling image
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24576 seconds with 12 queries