- This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
Viewing 10 posts - 1 through 10 (of 10 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hello,
I am trying to have say around 5 items in a list, and when one is hover over I would like an image to change. I just cannot figure out how to do this but I do have an example.
http://www.nationalspeedinc.com/about/
On the right hand side of the page they have 6 or so links, when you hover over one the image changes. I’ve been looking at their code and trying to google any type of examples but I am stumped on how to accomplish something like this.
Any ideas?
Thanks.
Check this out. If you stop before the javascript part, it does pretty much the same thing.
Ok, css sprites sound like they will work, but I am having trouble thinking of the html on how i have a list of 5 items and only one image container that changes. Any examples?
Thanks
Hey Nutt318, maybe this will help you on your way.
HTML:
CSS:
div#imageContainer {background: url('images/spriteImage.jpg'; background-position:0px 0px;}
jQuery/Javascript
$(document).ready(function(){
$('ul li a').mouseenter(function(){
$('ul li a').css('font-weight','normal');
currentRel = $(this).attr('rel');
backgroundOffset = currentRel * 200; //taken your images are all 200px in height
$('div#imageContainer').css('background-position','0px -' + backgroundOffset + 'px');
$(this).css('font-weight','bold');
});
});
This should work, try it out.
Hey rickylamerz,
Thanks for the help, I wish I knew more javascript.
Anyways, the top image of my sprite shows up but when i hover over the other links the image doesnt change.
Any ideas?
Thanks.
Could you link me to the site? Or provide me with the code?
Sent you a PM also, http://go-mcracing.com/about/ Is it OK to have the JavaScript in a .js file or does it need to be on that page?
Haven’t got any PM’s do you have an IM client so I can help out quicker?
.
Marked as Solved, Thanks for the help rickylamerz!