JavaScript: how to expand the layer after clicking the mouse

Source: Internet
Author: User

JavaScript: how to expand the layer after clicking the mouse

This article describes how to expand the layer after clicking the mouse in JavaScript. Share it with you for your reference. The specific analysis is as follows:

This section of JavaScript code allows you to expand the layer after clicking the mouse. The code is a little complicated and focuses on learning and researching. If you are interested, you can modify and simplify it.

?

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

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

<Html>

<Head>

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

<Title> layer expansion and collapse </title>

</Head>

<Body>

<Style type = "text/css">

DIV. clTopMenu {

Position: absolute;

Width: 101;

Height: 150;

Clip: rect (0,101 );

Visibility: hidden;

Z-index: 31;

Layer-background-color: # EEEEEE;

Background-color: #00 CCFF

}

DIV. clTopMenuBottom {

Position: absolute;

Width: 101;

Height: 3;

Clip: rect (0,101 );

Top: 11;

Layer-background-color: # CECFCE;

Background-color: #000099;

Z-index: 2

}

DIV. clTopMenuText {

Position: absolute;

Width: 91;

Left: 5;

Top: 15;

Font-family: "Arial", "Helvetica", "sans-serif ";

Font-size: 9pt;

Background-color: # EEEEEE;

Z-index: 1;

Color: #000000.

}

A: link {

Color: #000000;

Text-decoration: none

}

</Style>

<Script language = "JavaScript" type = "text/javascript">

Function lib_bwcheck () {// Browsercheck (needed)

This. ver = navigator. appVersion

This. agent = navigator. userAgent

This. dom = document. getElementById? 1:0

This. opera5 = this. agent. indexOf ("Opera 5")>-1

This. ie5 = (this. ver. indexOf ("MSIE 5")>-1 & this. dom &&! This. opera5 )? 1:0;

This. ie6 = (this. ver. indexOf ("MSIE 6")>-1 & this. dom &&! This. opera5 )? 1:0;

This. ie4 = (document. all &&! This. dom &&! This. opera5 )? 1:0;

This. ie = this. ie4 | this. ie5 | this. ie6

This. mac = this. agent. indexOf ("Mac")>-1

This. ns6 = (this. dom & parseInt (this. ver)> = 5 )? 1:0;

This. ns4 = (document. layers &&! This. dom )? 1:0;

This. bw = (this. ie6 | this. ie5 | this. ie4 | this. ns4 | this. ns6 | this. opera5)

Return this

}

Var bw = new lib_bwcheck ()

NPlace = 0

Var nNumberOfMenus = 2

Var nMwidth = 101

Var nPxbetween = 20

Var nFromleft = 10

Var nFromtop = 20

Var nBgcolor = '# CECFCE'

Var nBgcolorchangeto = '# 6380BC'

Var nImageheight = 11

Function makeNewsMenu (obj, nest ){

Nest = (! Nest )? "": 'Document. '+ nest + '.'

This.css = bw. dom? Document. getElementById (obj). style: bw. ie4? Document. all [obj]. style: bw. ns4? Eval (nest + "document. layers." + obj): 0;

This. evnt = bw. dom? Document. getElementById (obj): bw. ie4? Document. all [obj]: bw. ns4? Eval (nest + "document. layers." + obj): 0;

This. scrollHeight = bw. ns4? This.css.doc ument. height: this. evnt. offsetHeight

This. moveIt = B _moveIt; this. bgChange = B _bgChange;

This. slideUp = B _slideUp; this. slideDown = B _slideDown;

This. clipTo = B _clipTo;

This. obj = obj + "Object"; eval (this. obj + "= this ")

}

Function B _moveIt (x, y) {this. x = x; this. y = y; this.css. left = this. x; this.css. top = this. y}

Function B _bgChange (color) {if (bw. dom | bw. ie4) this.css. backgroundColor = color; else this.css. bgColor = color}

Function B _clipTo (t, r, B, l ){

If(bw.ns4){this.css. clip. top = t; this.css. clip. right = r; this.css. clip. bottom = B; this.css. clip. left = l

} Else this.css. clip = "rect (" + t + "," + r + "," + B + "," + l + ")";

}

Function B _slideUp (ystop, moveby, speed, fn, wh ){

If (! This. slideactive ){

If (this. y> ystop ){

This. moveIt (this. x, this. y-5); eval (wh)

SetTimeout (this. obj + ". slideUp ("+ ystop +", "+ moveby +", "+ speed +", '"+ fn +"', '"+ wh +"') ", speed)

} Else {

This. slideactive = false; this. moveIt (0, ystop); eval (fn)

}

}

}

Function B _slideDown (ystop, moveby, speed, fn, wh ){

If (! This. slideactive ){

If (this. y <ystop ){

This. moveIt (this. x, this. y + 5); eval (wh)

SetTimeout (this. obj + ". slideDown ("+ ystop +", "+ moveby +", "+ speed +", '"+ fn +"', '"+ wh +"') ", speed)

} Else {

This. slideactive = false; this. moveIt (0, ystop); eval (fn)

}

}

}

Function newsMenuInit (){

OTopMenu = new Array ()

Zindex = 10

For (I = 0; I <= nNumberOfMenus; I ++ ){

OTopMenu [I] = new Array ()

OTopMenu [I] [0] = new makeNewsMenu ('divtopmenu '+ I)

OTopMenu [I] [1] = new makeNewsMenu ('divtopmenubottom '+ I, 'divtopmenu' + I)

OTopMenu [I] [2] = new makeNewsMenu ('divtopmenutext' + I, 'divtopmenu '+ I)

OTopMenu [I] [1]. moveIt (0, nImageheight)

OTopMenu [I] [0]. clipTo (0, nMwidth, nImageheight + 3, 0)

If (! NPlace) oTopMenu [I] [0]. moveIt (I * nMwidth + nFromleft + (I * nPxbetween), nFromtop)

Else {

OTopMenu [I] [0]. moveIt (nFromleft, I * nImageheight + nFromtop + (I * nPxbetween ))

Otopmenupolici=02.16.css. zIndex = zindex --

}

Otopmenupolici=02.16.css. visibility = "visible"

}

}

Function topMenu (num ){

If (oTopMenu [num] [1]. y = nImageheight) oTopMenu [num] [1]. slideDown (oTopMenu [num] [2]. scrollHeight + 20, 10, 40, 'oss-pmenu ['+ num +'] [0]. clipTo (0, nMwidth, oTopMenu ['+ num +'] [1]. y + 3, 0) ', 'otopmenu [' + num + '] [0]. clipTo (0, nMwidth, oTopMenu ['+ num +'] [1]. y + 3, 0 )')

Else if (oTopMenu [num] [1]. y = oTopMenu [num] [2]. scrollHeight + 20) oTopMenu [num] [1]. slideUp (nImageheight, 10, 40, 'oss ['+ num +'] [0]. clipTo (0, nMwidth, oTopMenu ['+ num +'] [1]. y + 3, 0) ', 'otopmenu [' + num + '] [0]. clipTo (0, nMwidth, oTopMenu ['+ num +'] [1]. y + 3, 0 )')

}

Function menuOver (num) {oTopMenu [num] [1]. bgChange (nBgcolorchangeto )}

Function menuOut (num) {oTopMenu [num] [1]. bgChange (nBgcolor )}

Onload = newsMenuInit;

</Script>

<Div id = "divTopMenu0" class = "clTopMenu" align = "center" style = "height: 170; left: 20; top: 20 "> <span class =" css3 "> <a href =" # "onMouseOver =" menuOver (0) "onMouseOut =" menuOut (0) "onClick =" topMenu (0); if (bw. dom | bw. ie4) this. blur (); return false "> click to expand </a>

</Span>

<Div id = "divTopMenuText0" class = "clTopMenuText">

<Span class = "css3">

Click the back layer to expand JavaScript. Click the back layer to expand JavaScript.

</Span>

</Div>

<Div id = "divTopMenuBottom0" class = "clTopMenuBottom" style = "top: 11; height: 10"> </div>

</Div>

</Div>

</Body>

</Html>

I hope this article will help you design javascript programs.

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.