-
Notifications
You must be signed in to change notification settings - Fork 35
/
menu.ajax.html
129 lines (120 loc) · 3.66 KB
/
menu.ajax.html
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
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Выпадающее меню с AJAX</title>
<link rel="profile" href="https://gmpg.org/xfn/11"/>
<link rel="shortcut icon" href="https://anton.shevchuk.name/favicon.ico"/>
<link rel="stylesheet" href="css/styles.css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/code.js"></script>
<script type="text/javascript">
$(function () {
$('.topmenu ul li').hover(
function () {
let $this = $(this)
if ($this.find('ul').length === 0) {
let file = $(this).data('file')
let li = $(this)
$.ajax({
url: 'ajax/' + file + '.html',
beforeSend: function () {
li.addClass('loading')
},
success: function (data) {
li.append(data)
li.find('ul').stop(true, true)
li.find('ul').slideDown()
li.removeClass('loading')
}
})
} else {
$this.find('ul').stop(true, true)
$this.find('ul').slideDown()
}
$this.addClass('active')
},
function () {
let $this = $(this)
$this.find('ul').slideUp('fast')
$this.removeClass('active')
}
)
})
</script>
<style>
.topmenu ul, .topmenu ul li {
padding: 0;
display: inline;
margin: 0 2px 0 0;
}
.topmenu ul li {
float: left;
position: relative;
width: 140px;
}
.topmenu li a {
display: block;
padding: 10px 10px 10px 30px;
margin: 1px 0;
color: #0000FF;
text-decoration: none;
border: 1px solid #999;
background: url('images/window.gif') no-repeat 10px center;
}
.topmenu ul li a:HOVER {
color: #0000CC;
}
.topmenu ul ul {
display: none;
position: absolute;
top: 48px;
}
.topmenu li li {
display: block;
border-top: 0;
background: #fff;
z-index: 99;
}
.active {
background-color: #eee;
}
.loading {
background: url('images/ajax-loader.gif') no-repeat right;
}
article {
height: 240px;
padding: 20px;
position: relative;
}
</style>
</head>
<body>
<header>
<h1>Выпадающее меню</h1>
<h2>Простое и лаконичное</h2>
</header>
<main>
<article>
<div class="topmenu">
<ul>
<li class="drop" data-file="menu1"><a href="#" title="Меню 1">Меню 1</a></li>
<li class="drop" data-file="menu2"><a href="#" title="Меню 2">Меню 2</a></li>
<li class="drop" data-file="menu3"><a href="#" title="Меню 3">Меню 3</a></li>
</ul>
</div>
</article>
</main>
<footer>
© <a href="https://anton.shevchuk.name/jquery-book/">jQuery for beginners</a>
</footer>
<aside>
<nav>
<a href="menu.drop-down.html" title="go prev" rel="prev">Prev</a>
<a href="index.html#annex" title="back to Index" rel="index">Index</a>
<a href="#" title="reload" onclick="window.location.reload();return false">Reload</a>
</nav>
</aside>
</body>
</html>