Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    transform: translate < javascript control

    Hi,

    Is it possible that when a webpage loads I can have javascript change the class of a div from:

    .up {
    transform: translate(0px,-500px)
    transition: all 5s ease-in;
    }

    to

    .down {
    transform: translate(0px,0px)
    transition: all 5s ease-in;
    }

    Essentially I would like a div to move down into place from the top of screen to the middle of screen after the page has loaded.

    Some thing like this?:


    Code:
    <script type="text/javascript">
    function transform()
    {
       document.getElementById("content").className = "down";
    
    </script>
    
    
    <div id="content" class "up" onload="transform()">
    
    </div>
    </html>
    would this work or is there a better way?

    Adrian.
    Last edited by aster; 02-29-2012 at 12:45 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,174
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Well, it would if you called the script with <body onload>

    Code:
    <body onload="transform()">
    <div id="content" class "up" >
    </div>
    
    <script type="text/javascript">
    function transform(){
    document.getElementById("content").className = "down";
    alert (document.getElementById("content").className);
    }
    </script>

    But what is the point? Why not simply change the class name of the <div> "content" in the page code? But if you are tring to animate the <div> so that it moves slowly from page top to page middle then that is a quite different issue.
    Have a look at the many excellent scripts at http://www.vicsjavascripts.org.uk/


    “A gentleman is one who never hurts anyone's feelings unintentionally.” -
    Oscar Wilde (Irish Poet, Novelist, Dramatist and Critic, 1854-1900)
    Last edited by Philip M; 02-29-2012 at 01:40 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes moving the div slowly hence the "transition: all 5s ease-in"

    I know how to make a div move with a button click or mouse over being the trigger but to do it automatically on page load?

    Simply want the effect of a panel moving down the page into place when a viewer first loads the home page.

    Ill check your link out...
    Last edited by aster; 02-29-2012 at 09:16 PM.

  • #4
    New Coder
    Join Date
    Feb 2012
    Location
    England
    Posts
    59
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by aster View Post
    yes moving the div slowly hence the "transition: all 5s ease-in"

    I know how to make a div move with a button click or mouse over being the trigger but to do it automatically on page load?

    Simply want the effect of a panel moving down the page into place when a viewer first loads the home page.

    Ill check your link out...
    I'm defo no expert but won't a simple "onLoad" even handle this? *Edit* Nevermind you already tried that :P
    Last edited by MancunianMacca; 02-29-2012 at 10:07 PM. Reason: You already had the onLoad.

  • #5
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks to Philip M,

    inserted the body onload, now it works a charm.

    thanks again.


  •  

    Posting Permissions

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