/    Sign up×
Community /Pin to ProfileBookmark

Hi,

I have some html code similar to this :

[CODE]
<div><div onclick=”show_the_div2″>click me</div>

<div id=”div2″>Content</div>

</div>
[/CODE]

By clicking that div, the “content div” appears on the screen.
I want to have the content div, roll down to the screen, instead of appearing out of sudden. like its moves till it shows all the div. and the backward thing, by clicking that this div goes back and hide.

I hope I was clear enough.
Any help?

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledJan 24.2009 — i has never used mootools but that framework have some basic effect like slide content. you can see a demo at http://demos.mootools.net/Fx.Slide also, you will find there documentation on how to use it in case you want to try it.
Copy linkTweet thisAlerts:
@cootheadJan 24.2009 — Hi there asmith20002,

here is an example for you to try...
[color=navy]
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;

&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;

&lt;title&gt;expand and shrink div&lt;/title&gt;

&lt;style type="text/css"&gt;
body {
font-family:sans-serif;
font-size:0.8em;
background-color:#fc9;
}
#expand {
width:80px;
padding:5px;
border:3px double #999;
background-color:#fff;
text-align:center;
cursor:pointer;
display:none;
}
#container { <br/>
width:600px;
overflow:hidden;
background-color:#fff;
margin:auto;
}
#container #inner { <br/>
padding:10px;
}
#container p {
margin:0;
padding:10px;
text-align:justify;
text-indent:1.5em;
}
#container p:first-letter {
font-family:serif;
font-size:200%;
color:#600;
}
.brdr {
border:1px solid #999;
}
.go {
color:#090;
}
.stop {
color:#900;
}
&lt;/style&gt;

&lt;script type="text/javascript"&gt;

var c=0;
var test=true
var obj,obj1,obj2,hgt,exp,shr;
var speed=50;

if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
}
}

function init(){
obj=document.getElementById('expand');
obj1=document.getElementById('container');
hgt=document.getElementById('inner').offsetHeight;

obj.style.display='block';
obj1.className='';
obj1.style.height=0;

obj.onclick=function(){
if(test==true){
expandDiv();
test=false;
}
else {
shrinkDiv();
test=true;
}
}
}

function expandDiv() {
clearTimeout(shr);
obj1.style.height=c+'px';
obj1.className='brdr';
obj.firstChild.nodeValue='shrink';
obj.className='stop';

c+=20;
if(c&gt;=hgt) {
c=hgt;
clearTimeout(exp);
return;
}
exp=setTimeout('expandDiv()',50);
}

function shrinkDiv() {
clearTimeout(exp);
obj1.style.height=c+'px';
obj.firstChild.nodeValue='expand';
obj.className='go';

c-=20;
if(c&lt;0) {
c=0;
clearTimeout(shr);
obj1.style.height=0;
obj1.className='';
return;
}
shr=setTimeout('shrinkDiv()',50);
}
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;div id="expand" class="go"&gt;expand&lt;/div&gt;

&lt;div id="container" class="brdr"&gt;
&lt;div id="inner"&gt;
&lt;p&gt;
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin massa. Nam vehicula.
Morbi velit nisi, mollis id, ultrices luctus, adipiscing sit amet, lectus. Nunc rhoncus
nisl ac enim. Maecenas vestibulum dolor ut velit. Maecenas condimentum pulvinar purus.
Pellentesque ac ipsum. Curabitur sodales, elit vel molestie hendrerit, elit odio rhoncus tellus,
nec gravida enim urna id velit. Donec nec tellus. Vestibulum nulla. Curabitur enim arcu,
ornare id, placerat eget, nonummy vitae, mauris. Nulla rutrum semper odio. Duis vulputate
ornare mauris. Praesent eget nibh sed ante ultricies scelerisque. Duis eget felis ut arcu porta
bibendum. Mauris rutrum. Vivamus consectetuer purus sit amet mi. Suspendisse eu augue.
&lt;/p&gt;&lt;p&gt;
Quisque nec enim. Nullam elementum. Quisque rhoncus. Ut cursus, pede sit amet facilisis pretium,
est erat congue tortor, eget tincidunt metus augue in mauris. Sed id pede. Nam varius faucibus massa.
In orci. Suspendisse metus nunc, egestas non, porta a, fermentum interdum, mi. Nulla vel tellus nec
erat consectetuer molestie. Vivamus turpis erat, rhoncus sed, ornare vel, volutpat sagittis, nibh.
&lt;/p&gt;&lt;p&gt;
Nulla libero. Aliquam erat volutpat. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. *** sociis
natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut id mauris eget felis laoreet
semper. Maecenas venenatis erat et orci. Aenean interdum ligula sed nisi. Nulla vel lectus eu dolor porttitor
tempus. Proin at nisi fringilla pede feugiat luctus. Aenean id risus. Vestibulum a erat ac ipsum fringilla
feugiat. Cras mauris.
&lt;/p&gt;&lt;p&gt;

Donec lobortis, odio non ultrices commodo, urna eros ornare lectus, quis faucibus nisi nibh sit amet lectus.
Nam tristique, velit ac ullamcorper adipiscing, ligula justo ullamcorper augue, ut ullamcorper sem nisi sed
dolor. Proin at lectus. Nam sagittis euismod lorem. Vestibulum lobortis viverra sapien. Phasellus euismod,
nulla quis posuere convallis, tellus urna tincidunt augue, at gravida nisl diam non mi. Sed at metus. Mauris
risus augue, viverra non, varius a, ornare sit amet, dolor. Pellentesque sed est vel nulla dictum pretium.
Suspendisse potenti. Quisque rutrum pulvinar magna.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
[/color]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@asmith20002authorJan 24.2009 — Thanks a lot for the replies ?

@coothead

Its very nice, I'm gonna study your script. Your script does not "roll" the div down, its show some part of the div each time. like a curtain is falling.

However I need to learn it. It will come handy ^^

@ZeroKilled

I'd like to use this script.

Just, when I remove the "slide in" and "slide out" links from the html, the script stops working. I only need the toggle link. but these 3 links apparently work together. Any idea?

also, I need to know, what to change on the html, so that in some pages, I show it open by default, and in some other pages, I show it closed by default. Is that possible?
×

Success!

Help @asmith20002 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.19,
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,
)...