Why does it animate the element from begin of left not from it's position to 100 pixel left
$("selector").animate({left: "+100px"});
Why does it animate the element from begin of left not from it's position to 100 pixel left
$("selector").animate({left: "+100px"});
According to the documentation for jQuery's animate():
"If a value is supplied with a leading
+=
or-=
sequence of characters, then the target value is computed by adding or subtracting the given number from the current value of the property."
So, use this syntax:
$("div").animate({
left: "+=100px"
});
div {
position: absolute;
width: 20px;
height: 20px;
background-color: #CCC;
left: 200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>