Javascript: Sliding expansion and folding effect implemented by JS _ Javascript tutorial

Source: Internet
Author: User
Javascript: Sliding expansion and folding effects implemented by JS, Javascript tutorial

You need to write a slide, expand, and collapse effect. You can find a post of the carefree script and make it be applied to FF with a slight modification. The Code is as follows:

The following is a reference clip:

// Url: http://bbs.51js.com/thread-61646-1-1.html
// Author: sudden changes
// Modify: fengyan
Var act;
Function over (s, nMax ){
Var obj = document. getElementById (s );
Var h = parseInt (obj. offsetHeight );
If (h <nMax ){
Obj. style. height = (h + 2) + "px ";
ClearTimeout (act );
Act = setTimeout ("over ('" + s + "'," + nMax + ")", 10 );
}
}
Function out (s, nMin ){
Var obj = document. getElementById (s );
Var h = parseInt (obj. offsetHeight );
If (h> nMin ){
Obj. style. height = (h-2) + "px ";
ClearTimeout (act );
Act = setTimeout ("out ('" + s + "'," + nMin + ")", 10 );
}
}
Script
<Div id = "mytd" onmouseover = "over ('mytd ', 200);" onmouseout = "out ('mytd', 30);" style = "background: # eee; "> code instance: slide expansion/collapse of Layers

Carefree netizens Fangxiao9159After optimization:
The following is a reference clip:

Var intervalId = null;
Function move (id, state ){
Var obj = document. getElementById (id );
If (intervalId! = Null)
Window. clearInterval (intervalId );
Function change (){
Var h = parseInt (obj. offsetHeight );
Obj. style. height = (state = "down ")? (H + 2): (h-2 );
}
IntervalId = window. setInterval (change, 10 );
}
Script

Worry-free script-sudden changes
Related Article

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.