A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] simple javacript moving div

  1. #1
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173

    resolved [RESOLVED] simple javacript moving div

    I cant figure out why the Div wont move back to the left when i clock the link to activate the script...

    any takers?

    Actionscript Code:
    <script type="text/javascript">
    <!--


    function moveDiv()
    {
      var tempnum = 1;
      var the_style = getStyleObject("myDiv");
      var the_left = parseInt(the_style.left) + 100;
      var the_top = parseInt(the_style.top) + 0;
      if (document.layers)
      {
          if (tempnum==1){
              the_left = parseInt(the_style.left) + 100;
        the_style.left = the_left;
        the_style.top = the_top;
        tempnum=0;
          }else if (tempnum==0){
                  the_left = parseInt(the_style.left) - 300;
        the_style.left = the_left;
        the_style.top = the_top;
        tempnum=1;
          }
      }
      else
      {
         
          if (tempnum==1){
              the_left = parseInt(the_style.left) + 100;
              the_style.left = the_left + "px";
              the_style.top = the_top + "px";  
              tempnum=0;
          }else if(tempnum==0){
               the_left = parseInt(the_style.left) - 300;
               the_style.left = the_left + "px";
                the_style.top = the_top + "px";  
                tempnum=1;
          }
         

      }
    }

      function getStyleObject(objectId) {
        // cross-browser function to get an object's style object given its
        if(document.getElementById && document.getElementById(objectId)) {
        // W3C DOM
        return document.getElementById(objectId).style;
        } else if (document.all && document.all(objectId)) {
        // MSIE 4 DOM
        return document.all(objectId).style;
        } else if (document.layers && document.layers[objectId]) {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[objectId];
        } else {
        return false;
        }
        } // getStyleObject

    // -->
    </script>

  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    Boy oh boy...the code you're using is about 15 years old, and unfortunately isn't going to work properly.

    Here's how you could get the value of "left" on myDiv:

    Code:
    var left;
    try {
       // everybody but IE
       left = document.defaultView.getComputedStyle(document.getElementById("myDiv"), null).getPropertyValue("left");
    } catch(err) {
       // IE8 and below
       left = document.getElementById("myDiv").currentStyle.left;
    }
    alert(left);
    Last edited by rdoyle720; 03-24-2011 at 10:01 AM.

  3. #3
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    can you iterate more?

    how can I use the script you just gave me (which I understand) to move my div?

    Im basically looking for a way to make at least 3 divs independently move out from the side of the screen depending on which one you click, and then when you click again move back off of the screen.

    Unless you have a magic way to embed the facebook like api into flash, but the common consensus is that is impossible.

    Quote Originally Posted by rdoyle720 View Post
    Boy oh boy...the code you're using is about 15 years old, and unfortunately isn't going to work properly.
    Nothing like a throw back huh?

    can you link to the up to date reference libraries, so I can start getting with the times?
    Last edited by YBAB; 03-30-2011 at 12:29 PM.

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    If you want a quick and easy way to do something like this, I'd suggest something like JQuery (jquery.com). That gives you all sorts of easy to use options.

    http://api.jquery.com/animate/

  5. #5
    Senior Member
    Join Date
    Mar 2011
    Location
    Riverside ish...
    Posts
    173
    good god not another language to learn >_<

    thanks though, ima get on that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center