CSS + JS: How to automatically close the DIV layer menu when you click the text to pop up

Source: Internet
Author: User

CSS + JS: How to automatically close the DIV layer menu when you click the text to pop up

This example describes how to automatically close the DIV layer menu when you click a text pop-up in CSS + JS. Share it with you for your reference. The specific analysis is as follows:

Here, we use CSS + JS to achieve click on the text and then use an animation to expand a DIV layer menu. The menu will be closed automatically upon expiration, which is the effect of CSS combined with JS.

?

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

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

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

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

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

<Head>

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

<Title> CSS + JS pop-up DIV layer </title>

<Script type = "text/javascript">

Var w = 0;

Var h = 0;

Var mout;

Function emotion (){

Var oMenu = document. getElementById ("menu ");

If (w <= 50 ){

OMenu. style. display = "block ";

FnLarge ();

}

Else {

FnSmall ();

}

}

Function fnLarge (){

Var oMenu = document. getElementById ("menu ");

If (w <200 ){

W + = 50;

H + = 25;

OMenu. style. width = w + "px ";

OMenu. style. height = h + "px ";

Window. setTimeout ("fnLarge ()", 10 );

}

}

Function fnSmall (){

Var oMenu = document. getElementById ("menu ");

If (w> 0 ){

W-= 50;

H-= 25;

OMenu. style. width = w + "px ";

OMenu. style. height = h + "px ";

Window. setTimeout ("fnSmall ()", 5 );

}

Else {

OMenu. style. display = "none ";

}

}

</Script>

<Style type = "text/css">

Body {

Text-align: center;

}

P {

Cursor: pointer;

Margin: 0;

Padding: 0;

Font-size: 24px;

Display: inline;

}

Div a: link, div a: visited {

Color: #666;

Text-decoration: none;

}

Div a: hover {

Color: # FF6600;

Text-decoration: underline;

}

Div {

Border: 2px solid #666;

Background: # fff;

Margin: 5px auto;

Overflow: hidden;

Display: none;

Padding: 5px 10px;

}

Ul, li {

Margin: 0;

Padding: 0;

}

Li {

List-style: none;

Width: 70px;

}

Li. title {

Font-weight: bold;

}

</Style>

</Head>

<Body>

<P onclick = "emotion ();"> click this line of text! </P>

<Div id = "menu"

Onmouseout = "javascript: mout = setTimeout ('fnsmall () ', 2111 );"

OnMouseOver = "javascript: clearTimeout (mout);">

<Table border = "0" cellspacing = "0" cellpadding = "0">

<Tr>

<Td width = "80" valign = "top" align = "left">

<Ul>

<Li class = "title"> ASP </li>

<Li> <a href = "#" onclick = "fnSmall ();"> News </a> </li>

<Li> <a href = "#" onclick = "fnSmall ();"> Forum </a> </li>

<Li> <a href = "#" onclick = "fnSmall ();"> CMS </a> </li>

<Li> </li>

</Ul> </td>

<Td width = "80" valign = "top" align = "left">

<Ul>

<Li class = "title"> PHP </li>

<Li> <a href = "#" onclick = "fnSmall ();"> Article </a> </li>

<Li> <a href = "#" onclick = "fnSmall ();"> chat </a> </li>

<Li> <a href = "#" onclick = "fnSmall ();"> plug-in </a> </li>

<Li> <a href = "#" onclick = "fnSmall ();"> enterprise </a> </li>

</Ul>

</Td>

<Td width = "80" valign = "top" align = "left">

<Ul>

<Li class = "title"> JSP </li>

<Li> <a href = "#" onclick = "fnSmall ();"> AJAX </a> </li>

<Li> <a href = "#" onclick = "fnSmall ();"> JQUERY </a> </li>

<Li> <a href = "#" onclick = "fnSmall ();"> MYSQL </a> </li>

<Li> <a href = "#" onclick = "fnSmall ();"> JAVA </a> </li>

</Ul>

</Td>

</Tr>

</Table>

</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.