简体   繁体   中英

Jquery .animate not working for fixed position

This is my .animate function

<script>
       $(document).ready(function(){
$('#slide').click(function(){
$('#2guns').animate({right: 500},10000);
});
});
</script>

And this is the element I'm animating

 <div class="content">
            <button id="slide">slide</button>
           <img src="/home/varun/Documents/Crown/images/line.png" id="2guns" STYLE="position:absolute;left:1293px;">
        </div>

It works perfectly without the attribute

left:1293px;

Any solutions?

Here it is http://jsfiddle.net/kD3Zt/

 <div class="content">
        <button id="slide">slide</button>
       <img src="/home/varun/Documents/Crown/images/line.png" id="2guns" STYLE="position:absolute;left:1293px;">
    </div>

 $(document).ready(function(){
 $('#slide').click(function(){
 $('#2guns').animate({left: 200},10000);
 });
 });

Do this instead, element can't have both left and right as style

$('#2guns').animate({left: 500},10000);

DEMO

Why you want to give left, please specify...

I tried it with right and it works fine...

<div class="content">
            <button id="slide">slide</button>
           <img src="/home/varun/Documents/Crown/images/line.png" id="2guns" STYLE="position:absolute; right:0px;">
        </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM