Jump to content
brooke_theperson

jQuery Animate

Recommended Posts

Hey, so I have this simple jQuery function,but it is not working. When I click the div with the class "buttonup", the div with the class "thing" doesn't move. Can anyone tell me why this won't work?

 

$(document).ready(function(){    $('.buttonup').click(function(){        $('.thing').animate({left: '+=10px'}, 500);    });});

Share this post


Link to post
Share on other sites

"+=10px" isn't a valid CSS value.

 

What are you trying to do?

Share this post


Link to post
Share on other sites

This should work as long as the element's position property is set to "relative"

$('.thing').animate({left: '10px'}, 500);

Share this post


Link to post
Share on other sites

'+=10px' is a perfectly valid jquery value, it moves the div 10px further to right with every click, using '10px' just moves it right by 10px and no more.

<!DOCTYPE html><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <meta name="viewport" id="viewport" content="target-densitydpi=high-dpi,initial-scale=1.0,user-scalable=no" />        <title>Document Title</title>        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>        <script  type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>        <script type="text/javascript">               $(document).ready(function() {                    $('.buttonup').click(function() {                        $('.thing').animate({left: '+=10px'}, 500);                    });                });            }        </script>        <style type="text/css">           .thing {position: absolute; height: 200px; width: 200px; background-color: red; left: 0; top: 600px;}       </style>    </head>    <body>        <div class="thing"></div>        <input type="button" class="buttonup" value="press me">    </body></html>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...