Jump to content

Image change on mouse over


daveh33

Recommended Posts

I am writing a 5-star rating script and trying to get mouse over images to work.

 

I have my 5 stars for the user to click: -

 

<a href=\"#\" onclick=\"document.comment.rating.value='1'; return false;\"><img src=\"star01.gif\" border=\"0\" /></a> 
<a href=\"#\" onclick=\"document.comment.rating.value='2'; return false;\"><img src=\"star01.gif\" border=\"0\" /></a> 
<a href=\"#\" onclick=\"document.comment.rating.value='3'; return false;\"><img src=\"star01.gif\" border=\"0\" /></a> 
<a href=\"#\" onclick=\"document.comment.rating.value='4'; return false;\"><img src=\"star01.gif\" border=\"0\" /></a> 
<a href=\"#\" onclick=\"document.comment.rating.value='5'; return false;\"><img src=\"star01.gif\" border=\"0\" /></a> 

 

This sets the value of the hidden field no problem.

 

When the user clicks a star (e.g 4) I would like the first 4 stars image source to change - if anyone can help me with this it is much appreciated.

 

Thanking you in advanced!

Link to comment
Share on other sites

this should be posted in the javascript forum. Please don't post javascript questions in the php forum.

 

 

nevertheless,

you would set an id attribute on the img tags, like "star_1", etc., then you would create a function that has this in it

 

document.getElementById('star_1').src = "the new url";

 

and do that for all of the stars with lower numbers than the one clicked

Link to comment
Share on other sites

You don't need JavaScript.

 

For easier transition, make both images (the mouse over one and the default) and have a CSS hover update the CSS positioning of the image. Confused? Well, it's like this - make one image, put the default at the top and the hover over on the bottom. When you display it, have CSS display just the top one. Then using CSS's hover selector, change the positioning to display the bottom one. It has a cleaner effect then using JavaScript because the image is already loaded rather than having the browser load an image, which can be laggy. ;)

Link to comment
Share on other sites

You don't need JavaScript.

 

For easier transition, make both images (the mouse over one and the default) and have a CSS hover update the CSS positioning of the image. Confused? Well, it's like this - make one image, put the default at the top and the hover over on the bottom. When you display it, have CSS display just the top one. Then using CSS's hover selector, change the positioning to display the bottom one. It has a cleaner effect then using JavaScript because the image is already loaded rather than having the browser load an image, which can be laggy. ;)

 

well is it possible to change 4 other stars at the same time while hovering over just one star???

 

for example, if you hovered over image 4, image 1,2,3, AND 4 would have to change. Is that possible?

Link to comment
Share on other sites

well is it possible to change 4 other stars at the same time while hovering over just one star???

 

for example, if you hovered over image 4, image 1,2,3, AND 4 would have to change. Is that possible?

Yup! You don't need JavaScript. When I did my article rating system, I used all CSS and xHTML for it. It was a little excessive and would be simpler with JavaScript, but I chose not to use JavaScript.

Link to comment
Share on other sites

F-ing hot huh!? Use JavaScript and you get very buggy mouseovers where CSS === speed and sexiness! Yeah, I didn't create mine like that, but I still love my own little accomplishment. It was done a few years back when I didn't know that much. :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.