It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

JS Animation

JS Animation

Postby toothyXdip on Mon Jul 21, 2008 6:38 am

I am trying to learn JS animation

I have this script

Code: Select all
<html>
<head>
<title>Move Animation</title>
<style type="text/css">

body {
font:76% normal verdana,arial,tahoma;
}

h1, h2 {
font-size:1em;
}

#movObject {
position:absolute;
left:0px;
top:8em;
width:5em;
line-height:3em;
background:#99ccff;
border:1px solid #003366;
white-space:nowrap;
padding:0.5em;
}

</style>
<script type="text/javascript">

var mov = null;

function doMove() {
  mov.style.left = parseInt(mov.style.left)+1+'px';
  setTimeout(doMove,20);
}

function init() {
  mov = document.getElementById('movObject');
  mov.style.left = '0px';
  doMove();
}



window.onload = init;

</script>
</head>

<body>

<h1>Wazup</h1>
<h2>How can i make it stop half way?</h2>

<div id="movObject">
I am mov.
</div>

</body>
</html>


And i want to make the block stop moving half way (and startmoving the other way) but for right now how can i make it stop i know i have to check for when the style.left = 50% of the screen width with "IF" maybe but i cant look up how to do it because my laptop is on reserve power and i thought i would right this really fast. I will reply when i find charger.

Thanks,
toothyXdip
 
Posts: 0
Joined: Mon Jul 21, 2008 6:36 am

Postby rangana on Tue Jul 22, 2008 12:20 am

Limit it:
Code: Select all
function doMove() {
var end='450px'; // End limit of the div
if(mov.style.left==end) mov.style.left=end;
else mov.style.left = parseInt(mov.style.left)+1+'px';
setTimeout(doMove,1);
}

User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 4 guests