Jump to content

navigation that changes images on hover


Recommended Posts


I am trying to write a script that changes the background based on a navigation hover and I have got that part right.

What I would like to further do is when I move off the navigation bar it remembers the last image, if this makes sense.


Here is my code so far

        <a href="#">Home</a>
        <img src="pic2.jpg" alt="">
        <a href="#">About</a>
        <img src="pic3.jpg" alt="">
        <a href="#">Clients</a>
        <img src="pic4.jpg" alt="">
        <a href="#">Work</a>
        <img src="pic5.jpg" alt="">
        <a href="#">Contact</a>
        <img src="pic6.jpg" alt="">

  <img src="pic1.jpg" alt="">

and the css

.container {
  position: relative;
  overflow: hidden;
  margin: 100px auto;
  width: 800px;
  height: 500px;
  -webkit-box-shadow: 10px 10px 10px rgba(0,0,0,0.3);
  box-shadow: 10px 10px 10px rgba(0,0,0,0.3);
.container img {
  position: absolute;
  top: 0;
  left: 0;
  z-index: -60;

.container li img {
  position: absolute;
  top: 0;
  left: 800px;
  z-index: -50;
  -webkit-transition: all 1s ease;
  -moz-transition: all 1s ease;
  -o-transition: all 1s ease;
  -ms-transition: all 1s ease;
  transition: all 1s ease;
nav {
  width: 170px;
  height: 500px;
  background: #fff;
nav h1 {
  padding: 20px;
  color: #ccc;
  text-align: right;
  font: 25px Georgia, Times, serif;

ul {
  width: 800px;
  height: 500px;
  list-style: none;
li a {
  z-index: 1;
  display: block;
  padding-left: 20px;
  width: 150px;
  height: 30px;
  background: white;
  color: #444;
  text-decoration: none;
  font: 14px/30px Helvetica, Verdana, sans-serif;

li:nth-child(1) {
  padding-top: 50px;
li a:hover {
  background: #eee;

li a:hover + img {
  left: 0px;

I think I would need javascript in here somehow. I am a newbie at javascript so if someone can point me in teh right direction it would be much appreciated.



Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.