Shrink and expand content with buffering effect

Source: Internet
Author: User

Compatible with ie5.5 + firefox2.0 (because I only have these two browsers, I only tested them)

Many of blueidea's friends see the effects of shrinking and expanding content. The only difference is a buffer effect. If you don't talk about it, you will know it after you run it.
A fixed value is required for the maximum height. There is no good solution. If you are interested, please help us solve the problem. Thank you.
ThisCodeOther parts will not be updated and improved. If you need encapsulation, do it by yourself.

Release code for sharing and learning. Please respect others' works for commercial purposes !!!!! Copy code The Code is as follows: <HTML>
<Head>
<SCRIPT>
/*
By auntion
Qq 1, 82874972
Welcome to my friends who like JavaScript and Ajax + + QQ, and make common progress.
Usage
Call effect: Effect (1, 2 );
1 indicates the ID of the object to be changed.
Where 2 is: the control container ID can be obtained by using: This. parentnode. ID (parent tag ID)
Note: Do not repeat the Object ID.
*/
Function $ G (read_id) {return document. getelementbyid (read_id )}
Function effect (objectid, parentid ){
If ($ G (objectid). style. Display = 'None '){
Start (objectid, 'opens ');
$ G (parentid ). innerhtml = "<a href = # onclick = javascript: effect ('" + objectid + "', '" + parentid + "');> close </a>"
} Else {
Start (objectid, 'close ');
$ G (parentid ). innerhtml = "<a href = # onclick = javascript: effect ('" + objectid + "', '" + parentid + "');> open </a>"
}
}
Function start (objid, method ){
VaR boxheight = $ G (objid). offsetheight; // get the object height
VaR minheight = 5; // defines the minimum object height.
VaR maxheight = 130; // defines the maximum height of an object.
VaR boxaddmax = 1; // initial incremental value
VaR every_add = 0.15; // The increment of each pass (subtract) [the greater the value, the faster the speed]
VaR reduce = (boxaddmax-every_add );
VaR add = (boxaddmax + every_add );
If (Method = "close "){
VaR alter_close = function () {// construct a virtual [Descending] Loop
Boxaddmax/= reduce;
Boxheight-= boxaddmax;
If (boxheight <= minheight ){
$ G (objid). style. Display = "NONE ";
Window. clearinterval (boxaction );
}
Else $ G (objid). style. Height = boxheight;
}
VaR boxaction = Window. setinterval (alter_close, 1 );
}
Else if (Method = "Opens "){
VaR alter_opens = function () {// construct a virtual [incremental] Loop
Boxaddmax * = add;
Boxheight + = boxaddmax;
If (boxheight> = maxheight ){
$ G (objid). style. Height = maxheight;
Window. clearinterval (boxaction );
} Else {
$ G (objid). style. Display = "Block ";
$ G (objid). style. Height = boxheight;
}
}
VaR boxaction = Window. setinterval (alter_opens, 1 );
}
}
</SCRIPT>
<Style>
Body, Div, table {font-size: 12px ;}
# Control {width: 200; Background-color: # CCC; font-size: 12px; font-color: #333333; text-align: center ;}
# Control a {font-weight: 900; line-Height: 30px; color: #333333 ;}
. Test {Height: 130; width: 200; Background-color: # CCC; display: block; overflow: hidden ;}
. Style1 {
Font-size: 8px;
Color: # ffffff;
}
</Style>
</Head>
<Body>
<Div id = "control">
<Table width = "100%" Height = "30" border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<TD width = "100%" align = "center" bgcolor = "# 2dd5ff" id = "testtab"> <a href = "#" onclick = "effect ('test ', this. parentnode. ID); "> close </a> </TD>
</Tr>
</Table>
</Div>
<Div id = "test" class = "test">
<Table width = "100%" Height = "130" border = "0" cellpadding = "4" cellspacing = "0" bgcolor = "# eeeeee">
<Tr>
<TD colspan = "3" align = "center" valign = "TOP"> This <br>
<Br>
Yes <br>
No. <br>
II <br>
, <Br>
Very <br>
Positive <br>
Regular <br> </TD>
</Tr>
</Table>
</Div>
<Div id = "control">
<Table width = "100%" Height = "10" border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<TD width = "100%" align = "center" valign = "bottom" bgcolor = "#00c0f0"> <SPAN class = "style1"> ▲ </span> </TD>
</Tr>
</Table>
</Div>
<Br>
<Div id = "control">
<Table width = "100%" Height = "30" border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<TD width = "100%" align = "center" bgcolor = "# 2dd5ff" id = "test1tab"> <a href = "#" onclick = "effect ('test1 ', this. parentnode. ID); "> close </a> </TD>
</Tr>
</Table>
</Div>
<Div id = "test1" class = "test">
<Table width = "100%" Height = "130" border = "0" cellpadding = "4" cellspacing = "0" bgcolor = "# eeeeee">
<Tr>
<TD colspan = "3" align = "center" valign = "TOP"> This <br>
<Br>
Yes <br>
No. <br>
1 <br>
, <Br>
Very <br>
Positive <br>
Regular <br> </TD>
</Tr>
</Table>
</Div>
<Div id = "control">
<Table width = "100%" Height = "10" border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<TD width = "100%" align = "center" valign = "bottom" bgcolor = "#00c0f0"> <SPAN class = "style1"> ▲ </span> </TD>
</Tr>
</Table>
</Div>
</Body>
</Html>

Both are closed.<Br/> <style> body, Div, table {font-size: 12px; }# control {width: 200; Background-color: # CCC; font-size: 12px; font-color: #333333; text-align: center;} # control a {font-weight: 900; line-Height: 30px; color: #333333 ;}. test {Height: 130; width: 200; Background-color: # CCC; display: block; overflow: hidden ;}. style1 {font-size: 8px; color: # ffffff ;} </style> <Table width = "100%" Height = "30" border = "0" cellpadding = "0" cellspacing = "0"> <tr> <TD width =" 100% "align =" center "bgcolor =" # 2dd5ff "id =" testtab "> close </TD> </tr> </table> <Table width =" 100% "height = "130" border = "0" cellpadding = "4" cellspacing = "0" bgcolor = "# eeeeee"> <tr> <TD colspan = "3" align = "Center "valign =" TOP "> </P> <p> Yes </P> <p> second </P> <p> </P> <p>, </P> <p> very </P> <p> positive </P> <p> normal </TD> </tr> </table> <Table width = "100%" Height = "10" border = "0" cellpadding = "0" cellspacing = "0"> <tr> <TD width = "100%" align = "center" valign = "bottom" bgcolor = "#00c0f0"> <SPAN class = "style1"> ▲ </span> </TD> </tr> </table> <Table width = "100%" Height = "30" border = "0" cellpadding = "0" cellspacing = "0"> <tr> <TD width = "100%" align = "center" bgcolor = "# 2dd5ff" id = "test1tab"> close </TD> </tr> </table> <Table width = "100%" Height = "130" border = "0 "cellpadding =" 4 "cellspacing =" 0 "bgcolor =" # eeeeee "> <tr> <TD colspan =" 3 "align =" center "valign =" TOP "> This </P> <p> Yes </P> <p> 1 </P> <p>, </P> <p> very </P> <p> positive </P> <p> normal </TD> </tr> </table> <Table width = "100%" Height = "10" border = "0" cellpadding = "0" cellspacing = "0"> <tr> <TD width = "100%" align = "center" valign = "bottom" bgcolor = "#00c0f0"> <SPAN class = "style1"> ▲ </span> </TD> </tr> </table> <p>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.