/    Sign up×
Community /Pin to ProfileBookmark

how to make an object animate-grow ?

hi,
i got an object i want to animate its width.

can i use this ?:
document.getElementById(“target”).style.width=w;

if so how do i ‘animate’ it (say from width=1 to width=500)?
and how can i change the ‘speed’ of the animation ?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 25.2005 — if your object is an image, increasing/decreasing it's size will definitelly ruin it's accuracy, as HTML and javascript are "bitmap" oriented... Flash will do that job properly.
Copy linkTweet thisAlerts:
@ofirauthorJul 25.2005 — it is not.

lets say a DIV
Copy linkTweet thisAlerts:
@KorJul 25.2005 — ok, in theory u should use a function which will add a [b]step[/b] number of pixels. This function is to be re-run/stopped using setTimeout(function,time) / clearTimeout() methods. The speed of growth can be controlled both by the set step and by the [b]time[/b] parameter of the setTimeout.
Copy linkTweet thisAlerts:
@ofirauthorJul 25.2005 — can u writ me the function?

to grow a div from width=1 to width=200?
Copy linkTweet thisAlerts:
@KorJul 25.2005 — here's a basic example:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<style type="text/css">
<!--
#mydiv{
background-color: #FF0000;
height: 10px;
width: 1px;

}
-->
</style>
<script type="text/javascript">
var s = 4;//step of growth in px;
var d = 80;//delay in milliseconds
var lim = 200;//the max width in px
function grow(){
var obj = document.getElementById('mydiv');
var w=obj.offsetWidth+s;
if(w>=lim){obj.style.width = lim+'px';clearTimeout(setT)}
else{obj.style.width = w+'px';var setT=setTimeout('grow()',d)}
}
</script>
</head>
<body>
<a href="#" onclick="grow();return false">grow</a><br>
<br>
<div id="mydiv"></div>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@ofirauthorJul 25.2005 — PERFECT !

tnx
Copy linkTweet thisAlerts:
@ofirauthorJul 25.2005 — p.s :

is there a way to make it grow from the middle to both sides?
Copy linkTweet thisAlerts:
@KorJul 25.2005 — nest the div in another div and give a center align

<div align="center">

<div id="mydiv"></div>

</div>
Copy linkTweet thisAlerts:
@ofirauthorJul 25.2005 — P-e-r-f-e-c-t-o !!
×

Success!

Help @ofir spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...