Method for js to implement slow div layer contraction and expansion

Source: Internet
Author: User

Method for js to implement slow div layer contraction and expansion

This article describes how to implement slow div layer contraction and expansion in JavaScript. Share it with you for your reference. The specific analysis is as follows:

This is a special effect code for layer scaling and expansion. It has a bit of animation effect and is slow to expand. It looks good if it is jointly created by DIV + JS. Without content constraints, the speed of contraction and expansion can be controlled, and the height and cycle time can also be changed.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN"

Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>

<Html xmlns = "http://www.w3.org/1999/xhtml">

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">

<Title> layer shrinkage </title>

<Script type = "text/javascript">

Var mh = 30; // height

Var step = 1; // The amount of changes each time

Var MS = 10; // cycle time

Function toggle (o ){

If (! O. tid) o. tid = "_" + Math. random () * 100;

If (! Window. toggler) window. toggler = {};

If (! Window. toggler [o. tid]) {

Window. toggler [o. tid] = {

Obj: o,

MaxHeight: o. offsetHeight,

MinHeight: mh,

Timer: null,

Action: 1

};

}

O. style. height = o. offsetHeight + "px ";

If (window. toggler [o. tid]. timer) clearTimeout (window. toggler [o. tid]. timer );

Window. toggler [o. tid]. action * =-1;

Window. toggler [o. tid]. timer = setTimeout ("anim ('" + o. tid + "')", MS );

}

Function anim (id ){

Var t = window. toggler [id];

Var o = window. toggler [id]. obj;

If (t. action <0 ){

If (o. offsetHeight <= t. minHeight ){

ClearTimeout (t. timer );

Return;

}

}

Else {

If (o. offsetHeight> = t. maxHeight ){

ClearTimeout (t. timer );

Return;

}

}

O. style. height = (parseInt (o. style. height, 10) + t. action * step) + "px ";

Window. toggler [id]. timer = setTimeout ("anim ('" + id + "')", MS );

}

</Script>

<Style type = "text/css">

Div. xx {

Border: solid 1px; overflow: hidden;

}

Div. xx h5 {

Border: solid 1px; border-width: 0 0 1px;

Padding: 0; margin: 0; height: 28px;

Line-height: 30px; cursor: pointer;

Background: # eee;

}

</Style>

</Head>

<Body>

<Div class = "xx">

<P> the configuration video tutorial of Tomat6.0 is in the AVI movie format, which is more appropriate than the tutorial of the graphic version,

Users who do not configure Tomcat should not miss it. video capturing is troublesome,

I tried it multiple times but I still caught a hard job. You will do it. </P>

</Div>

</Body>

</Html>

I hope this article will help you design javascript programs.

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.