javascript - Jquery hover - How to make background color animation - Stack Overflow

<div class="post_each"><h1 class="post_title">Apartamentos 1 odo<h1

<div class="post_each">
    <h1 class="post_title">Apartamentos 1 odo</h1>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb last" src="1.jpg"/>
</div>
<div class="post_each">
    <h1 class="post_title">Apartamentos 2 odo</h1>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb last" src="1.jpg"/>
</div>
<script type="text/javascript">
    $('img.thumb').hover(function {
        $(this).animate({"background" : "white"}, 600);
    });
</script>

hover() is not working at all. I just try to set either background color or border size should be increased when mouse hover.

<div class="post_each">
    <h1 class="post_title">Apartamentos 1 odo</h1>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb last" src="1.jpg"/>
</div>
<div class="post_each">
    <h1 class="post_title">Apartamentos 2 odo</h1>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb" src="1.jpg"/>
    <img class="thumb last" src="1.jpg"/>
</div>
<script type="text/javascript">
    $('img.thumb').hover(function {
        $(this).animate({"background" : "white"}, 600);
    });
</script>

hover() is not working at all. I just try to set either background color or border size should be increased when mouse hover.

Share Improve this question edited Jan 27, 2012 at 6:53 Sameera Thilakasiri 9,50810 gold badges53 silver badges87 bronze badges asked Jan 1, 2012 at 10:45 user1124927user1124927 1
  • Unless you've got another plugin, or you're using jQuery UI, jQuery can't animate colours. – David Thomas Commented Jan 1, 2012 at 10:47
Add a ment  | 

3 Answers 3

Reset to default 4

You can’t animate colors (at least this way), only properties with one numeric value are allowed. There is a separate color animation plugin you need to add.

That anonymous function is missing parentheses:

$('img.thumb').hover(function () {

You don't need jquery....

.thumb {
background: #000;
transition: 0.5s;
-moz-transition: 0.5s;
-webkit-transition: 0.5s;
-o-transition: 0.5s;}

.thumb:hover {
background: #fff;
transition: 0.5s;
-moz-transition: 0.5s;
-webkit-transition: 0.5s;
-o-transition: 0.5s;}

Demo here

you can use color plugin.. reference

$('img.thumb').hover(function(){
   $(this).animate({ backgroundColor: 'white' }, 600);
});

you can also refer previous threads jQuery backgroundColor animation and jQuery animate backgroundColor

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742365500a4430208.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信