#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Posts
    977
    Rep Power
    11

    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
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    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?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,175
    Rep Power
    184
    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
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    36
    Rep Power
    1
    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

    • web_loone08 agrees : Your right, but that's why I also added my comments about positioning.

IMN logo majestic logo threadwatch logo seochat tools logo