Javascript to implement navigation menu effects with a drop-down menu

Source: Internet
Author: User

Javascript to implement navigation menu effects with a drop-down menu

This example describes how to implement the navigation menu of a menu with a drop-down menu in javascript. Share it with you for your reference. The specific implementation method is as follows:

?

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

<! 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> navigation menu with a drop-down menu </title>

<Style type = "text/css">

Body {font-family: Verdana; font-size: 12px; line-height: 1.5 ;}

A {color: #000; text-decoration: none ;}

A: hover {color: # F00 ;}

# Menu {width: 500px; height: 28px; margin: 0 auto; border-bottom: 3px solid # E10001 ;}

# Menu ul {list-style: none; margin: 0px; padding: 0px ;}

# Menu ul li {float: left; margin-left: 2px ;}

# Menu ul li a {display: block; width: 87px; height: 28px; line-height: 28px; text-align: center; font-size: 14px ;}

# Menu ul li a # current {font-weight: bold; color: # fff ;}

# Menu ul li ul {border: 1px solid # ccc; display: none; position: absolute ;}

# Menu ul li {float: none; width: 87px; background: # eee; margin: 0 ;}

# Menu ul li a {background: none ;}

# Menu ul li a: hover {background: #333; color: # fff ;}

# Menu ul li: hover ul {display: block ;}

# Menu ul li. sfhover ul {display: block ;}

</Style>

<Script type = "text/javascript"> <! -- // --> <! [CDATA [//> <! --

Function menuFix (){

Var sfEls = document. getElementById ("menu"). getElementsByTagName ("li ");

For (var I = 0; I <sfEls. length; I ++ ){

SfEls [I]. onmouseover = function (){

This. className + = (this. className. length> 0? "": "") + "Sfhover ";

}

SfEls [I]. onMouseDown = function (){

This. className + = (this. className. length> 0? "": "") + "Sfhover ";

}

SfEls [I]. onMouseUp = function (){

This. className + = (this. className. length> 0? "": "") + "Sfhover ";

}

SfEls [I]. onmouseout = function (){

This. className = this. className. replace (new RegExp ("(? | ^) Sfhover \ B "),

"");

}

}

}

Window. onload = menuFix;

// --> <!]>

</Script>

</Head>

<Body>

<Div id = "menu">

<Ul>

<Li> <a id = "current" href = "#"> homepage </a> </li>

<Li> <a href = "#"> webpage layout </a>

<Ul>

<Li> <a href = "#"> adaptive width </a> </li>

<Li> <a href = "#"> fixed width </a> </li>

</Ul>

</Li>

<Li> <a href = "#"> web tutorial </a>

<Ul>

<Li> <a href = "#"> getting started </a> </li>

<Li> <a href = "#"> video tutorial </a> </li>

<Li> <a href = "#"> FAQs </a> </li>

</Ul>

</Li>

<Li> <a href = "#"> web instance </a> </li>

<Li> <a href = "#"> Common Code </a> </li>

</Ul>

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