Jump to content
#StayAtHome ×
Sign in to follow this  
lional

navigation that changes images on hover

Recommended Posts

Hi

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

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

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

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.

 

 

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

×
×
  • 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.