Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-29-2012, 12:40 PM   PM User | #1
aster
New to the CF scene

 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
aster is an unknown quantity at this point
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..
aster is offline   Reply With Quote
Old 02-29-2012, 01:22 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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)
__________________

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.

Last edited by Philip M; 02-29-2012 at 01:40 PM..
Philip M is offline   Reply With Quote
Old 02-29-2012, 09:13 PM   PM User | #3
aster
New to the CF scene

 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
aster is an unknown quantity at this point
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..
aster is offline   Reply With Quote
Old 02-29-2012, 10:06 PM   PM User | #4
MancunianMacca
New Coder

 
Join Date: Feb 2012
Location: England
Posts: 59
Thanks: 12
Thanked 2 Times in 2 Posts
MancunianMacca is an unknown quantity at this point
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.
MancunianMacca is offline   Reply With Quote
Old 02-29-2012, 11:13 PM   PM User | #5
aster
New to the CF scene

 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
aster is an unknown quantity at this point
Thanks to Philip M,

inserted the body onload, now it works a charm.

thanks again.
aster is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:23 PM.


Advertisement
Log in to turn off these ads.