4

Sorry for my English.

A friend of mine asked me to help him to build a HTML page. I just know a little bit of CSS, and know absolutely nothing about JavaScript or jQuery. All the code I wrote was from Google.

You can get what I really want in the picture, and I just finish the first step, the rollover animation works now, you can download the zip file here(http://www.hitbang.cn/stackoverflow.zip).

alt text

But I can't animate the color of the text at the same time ,and the picture and text's layout is the second problem that I need your help to overcome, CSS layout is so complicated!

Here is part of my code ,and you can download the whole code, if you help me correct my code, you can email me.

<div id="rightsidebar">
 <div id="yuepingTitle">
 </div>

 <div id="reviewContent">
  <ul id="reviewList">
    <li><a href="#">1</a></li>
    <li><a href="#">2</a></li>
    <li><a href="#">3</a></li>
    <li><a href="#">4</a></li>
    <li><a href="#">5</a></li>
    <li><a href="#">6</a></li>
    <li><a href="#">7</a></li>
  </ul>
 </div>
</div>

Javascript

$(function(){
$('#reviewList a')
  .css( {backgroundPosition: "0px 0px"} )
  .mouseover(function(){
   $(this).stop().animate({backgroundPosition:"(0px -692px)"}, {duration:300})
  })
  .mouseout(function(){
   $(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:200, complete:function(){
    $(this).css({backgroundPosition: "0px 0px"})
   }})
  })
});

CSS:

ul#reviewList {list-style:none;margin:0 ;padding:18px 0px 0px 6px;}

ul#reviewList li {width:266px;float:left;margin:0px 0px 1px 0px;padding:0;}

ul#reviewList li a {display:block;height:106px;color:#FFF;text-decoration:none;}

ul#reviewList a {background:url(img/1.jpg) no-repeat 0px 0px;}
2
  • 3
    Hey, don't put yourself down, your English wasn't that bad! ;) Commented Sep 7, 2010 at 5:05
  • 1
    I've certainly read a lot worse :) From native English speakers as well :P Commented Sep 7, 2010 at 5:10

1 Answer 1

3

I don't think you can animate colors with just jQuery. You need a plugin like jQuery UI. Then you can do something like this:

$(this).stop().animate({backgroundPosition:"(0px -692px)", color: "#123456"}, {duration:300})
Sign up to request clarification or add additional context in comments.

2 Comments

The code I posted works , I just don't know how to make the text animate the color while the background is changing.
Right, and in order to animate the text color, you need more than just jQuery. If you were to also include jQuery UI, you'd be able to add the color property to your animate object like in the code I posted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.