Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animate border color on hover?

Tags:

jquery

Using a color plugin to animate background color on hover.

$(function() {
    $('.listing-2 li a').mouseover(function() {
        $(this).animate({
            backgroundColor: "#0e7796"
        }, 'fast');
    });
    $('.listing-2 li a').mouseout(function() {
        $(this).animate({
            backgroundColor: "#d6f2c5"
        }, 'fast');
    });
});

How can I do the same for border color?

like image 607
Mike Avatar asked May 01 '09 22:05

Mike


4 Answers

Found in google

    $('.listing-2 li a').mouseover(function() {
    $(this).animate({ borderTopColor: "#0e7796" }, 'fast');
});
$('.listing-2 li a').mouseout(function() {
    $(this).animate({ borderTopColor: "#fff" }, 'fast');
});

it must be a "borderTopColor" (or left, right, bottom) instead of "borderColor".

like image 108
Mike Avatar answered Sep 29 '22 14:09

Mike


To animate the color of the entire border use:

$(this).animate({ borderTopColor: '#59b4de', borderLeftColor: '#59b4de', borderRightColor: '#59b4de', borderBottomColor: '#59b4de' }, 'fast');

Apparently, you need to specify them all.

like image 27
C. Spencer Beggs Avatar answered Sep 29 '22 13:09

C. Spencer Beggs


I had a similar issue. I apparently didn't have the jQuery-UI file attached to my document. Once I attached it. Everything works perfectly with "C. Spencer Beggs" answer.

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
like image 5
iRebel_85 Avatar answered Sep 29 '22 14:09

iRebel_85


this works also.

$("div.item").hover(function() {
    $(this).stop().animate({"border-color": "#999999"}, "slow");
},
function() {
    $(this).stop().animate({"border-color": "#BFBFBF"}, "slow");
});
like image 5
michael Avatar answered Sep 29 '22 14:09

michael