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 change image
Old 04-06-2007, 03:59 PM Re: javascript change image
Junior Talker

Posts: 3
Name: Cory Barnes
Trades: 0
Hi, is there a way to modify this script so the image will change when the mouse moves over the image, instead of clicking on it?
corybarnes is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-07-2007, 12:21 AM Re: javascript change image
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Cory you would basically want to call the replaceImg function by using an onmouseover event. You could have the onmouseover on either the <a> or the <img>. Which you would choose would depend on if you want the img to be a link or not.

So you might have something like:

HTML Code:
<a href="pathToSomeFile" onmouseover=replaceImg('img002_image.jpg');><img src="img002_thumb.jpg" alt="Image" /></a>
or

HTML Code:
<img onmouseover=replaceImg('img002_image.jpg'); src="img002_thumb.jpg" alt="Image" />
The script itself would be the same

HTML Code:
<script type="text/javascript">
 function replaceImg(path) {
     var imgDest = document.getElementById('image');
    var imgSrc = path;
    imgDest.setAttribute("src", imgSrc);
    }
</script>
There are actually many different ways to do this. If you search for things like 'image swap' or 'image rollover' you can probably find tutorials on how. You can even swap images using only css, though it would require different html than was used here.

I hope that helps.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 04-07-2007, 09:49 AM Re: javascript change image
Junior Talker

Posts: 3
Name: Cory Barnes
Trades: 0
Perfect...thank you!
corybarnes is offline
Reply With Quote
View Public Profile
 
Old 04-07-2007, 12:51 PM Re: javascript change image
Extreme Talker

Posts: 169
Trades: 0
at least the page already looks better than the old one.
And honestly, it's always a lot of work, especially when you are starting out and doing stuff manually, but you're getting there and learning on the way. Your doing it the good way and that's what counts.
__________________
George Bush would never take me alive.
MJM_RDS is offline
Reply With Quote
View Public Profile
 
Old 04-10-2007, 09:11 PM Re: javascript change image
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Glad to help Cory.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 05-04-2007, 09:16 AM Re: javascript change image
Junior Talker

Posts: 3
Name: Cory Barnes
Trades: 0
Here's an added twist...is it possible to add a text caption below each large image, and have those captions change when the image is changed?
corybarnes is offline
Reply With Quote
View Public Profile
 
Old 05-12-2007, 12:59 PM Re: javascript change image
Extreme Talker

Posts: 169
Trades: 0
Quote:
Originally Posted by corybarnes View Post
Here's an added twist...is it possible to add a text caption below each large image, and have those captions change when the image is changed?
Yeah. If you add a p element with an ID, say "description" you can add something like this:
Code:
document.getElementById('description').textContent = "descriptive text";
My only concern is that I think IE6 and below doesn't support textContent, but I'm not sure. Then you'd need to determine the user agent and then use textContent or innerText (I belive this was the IE only property).
Now to make this compatible with the script you already have you don't need to do all too much.
Code:
function replaceImg(path,desc) {
  var imgDest = document.getElementById('image');
  var imgSrc = path;
  imgDest.setAttribute("src", imgSrc);
  document.getElementById('description').textContent = desc;
}
And then whenever you call it, use something like this inside of you img tag:
Code:
onmouseover=replaceImg('img002_image.jpg','In this image there is nothing');
Of course to make it a bit more beautiful, well I think it would be more beautiful, if you created an array inside of your JS that has all your descriptions stored and then just passed the number of which description to use... a switch statememnt could do that, or you could actually use the filename as well. Which is the ebst Ic annot say, do what works for you.
__________________
George Bush would never take me alive.
MJM_RDS is offline
Reply With Quote
View Public Profile
 
Old 05-14-2007, 01:16 AM Re: javascript change image
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Here's an added twist...is it possible to add a text caption below each large image, and have those captions change when the image is changed?
like so;
http://www.candsdesign.co.uk/page-te...ery/layout.asp
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-14-2007, 07:13 PM Re: javascript change image
Extreme Talker

Posts: 169
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Take that, now just change the code so the used space is always the same, because seriously, that is crap the way the page height always alters... and now that usability is doubtable.
__________________
George Bush would never take me alive.
MJM_RDS is offline
Reply With Quote
View Public Profile
 
Old 07-31-2009, 06:39 AM Re: javascript change image
Junior Talker

Posts: 2
Trades: 0
Hi,
I am new here and I know this is an old thread, but could some one tell me what I am doing wrong? I don't care about the mouse pass over, I would like to be able to click the thumbs to change the picture.

http://www.chaoticreefer.net/RC/Emaxx/ebay/

I tried looking into ExpressoDan's example file, but I couldn't find anything that would give me a clue.

I have built many basic HTML pages, but this is my first time trying to change pictures. Any help will be appreciated. Thanks.

Last edited by chaoticreefer; 07-31-2009 at 06:43 AM.. Reason: typo corrections
chaoticreefer is offline
Reply With Quote
View Public Profile
 
Old 07-31-2009, 02:05 PM Re: javascript change image
Extreme Talker

Posts: 169
Trades: 0
The images don't exist, what do you expect?
http://www.chaoticreefer.net/RC/Emax...pictures/2.jpg
to
http://www.chaoticreefer.net/RC/Emax...pictures/7.jpg
Don't exist and thus cannot be displayed.

Otherwise the script should work fine.

You should also know this, you seem like an idiot if your entire ebay offer is in caps. Why are you shouting at the customer?
__________________
George Bush would never take me alive.
MJM_RDS is offline
Reply With Quote
View Public Profile
 
Old 07-31-2009, 03:23 PM Re: javascript change image
Junior Talker

Posts: 2
Trades: 0
Yeah, I figured out the problem couple hours ago, but I had to rush out to take my kids to school. The files were there, but the file extensions were upper case. I hate it when programs make them upper case.

As for eBay description, no need to call me an idiot, since I wasn't the freaking seller. I just copied and pasted the auction I won. It's better to know the facts then assuming things.

Last edited by chaoticreefer; 07-31-2009 at 03:27 PM..
chaoticreefer is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to javascript change 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.39992 seconds with 12 queries