Apoorva sahay
Apoorva sahay

Reputation: 1930

.animate not working along with .mouseenter/.mouseleave events?

I have a div as follows.

html:

<div id="leftdock"></div>

css:

#leftdock
{
    position: absolute;
    float:left;
    height: 400px;
    width: 200px;
    margin-left: -50px;
    border-radius: 0px 10px 10px 0px;
    background-color: #BADA7F;
    top: 30%;
}

following javascripts using jQuery:

$(document).ready(function () {
    $('#leftdock').mouseenter(function () {
        $(this).animate({
        margin-left: "-25px"
        }, 500);
    });

    $('#leftdock').mouseleave(function () {
        $(this).animate({
        margin-left: "-25px"
        }, 500);
    });
});

But with this the animation does not work. My div margin-left is not changing with mouseenter/leave even.

Upvotes: 0

Views: 119

Answers (2)

j08691
j08691

Reputation: 208032

Change

margin-left: "-25px"

to

marginLeft: "-25px"

jsFiddle example

Upvotes: 1

Anoop
Anoop

Reputation: 23208

This may solve your problem

$(document).ready(function () {
    $('#leftdock').mouseenter(function () {
        $(this).animate({
        'margin-left': -25
        }, 500);
    });

    $('#leftdock').mouseleave(function () {
        $(this).animate({
        'margin-left': -25
        }, 500);
    });
});

Upvotes: 2

Related Questions