January 10th, 2014, 04:36 AM
-
Simple animation
Hi,
I have this code, but it doesn't seem to work.
Can anyone see what's wrong with it?
PHP Code:
$(document).ready(function() {
$('#move').click(function() {
$('#box2').animate({'left' : '400px'}, 1000);
});
});
<a href="#">click</a>
Thanks
January 10th, 2014, 05:58 AM
-
You've spent 10 years in this forum, and you still haven't come to realize that "My code don't work" does not contain sufficient information to fix your problem?
We can't read your mind. We can't see through your eyes. We can't access your computer through telepathy. We're normal people limited to the 5 human senses. If you want us to help you with a problem, you have to actually describe it. With text and such, you know?
Right now, all I see is a JavaScript code snippet (but no script element) trying to access elements not shown in your extract. So what's the problem?
January 11th, 2014, 03:12 PM
-
Originally Posted by toolman
Hi,
I have this code, but it doesn't seem to work.
Can anyone see what's wrong with it?
PHP Code:
$(document).ready(function() {
$('#move').click(function() {
$('#box2').animate({'left' : '400px'}, 1000);
});
});
<a href="#">click</a>
Thanks
You should use "marginLeft", not "left"; as you need to set the CSS position property of the "box2" element (relative | fixed | absolute - setting the element to any of these three positions will allow you to use "left" to move the element from left to right) to accommodate moving the "box2" element "left". You also need to give your "a" tag an id of "move".
Last edited by web_loone08; January 11th, 2014 at 03:44 PM.
Reason: Included More Specific Details
January 19th, 2014, 02:24 PM
-
Originally Posted by web_loone08
You should use "marginLeft", not "left"; as you need to set the CSS position property of the "box2" element (relative | fixed | absolute - setting the element to any of these three positions will allow you to use "left" to move the element from left to right) to accommodate moving the "box2" element "left". You also need to give your "a" tag an id of "move".
He doesn't necessarily want to use margin-left, because it may push around other elements. I would much rather set the position, then move it instead of just moving it by its margin and hoping nothing was next to it.
Comments on this post