-
Notifications
You must be signed in to change notification settings - Fork 35
/
offset-and-position.html
75 lines (73 loc) · 2.45 KB
/
offset-and-position.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
<!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>Манипуляции с DOM: "offset()" и "position()"</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>
<style>
article {
position: relative;
height: 480px;
}
.square {
width: 100px;
height: 100px;
top: 40px;
left: 40px;
border-radius: 4px;
box-shadow: 0 0 4px 0 rgba(0,0,0,0.75);
background: #ff7300;
position: absolute;
}
</style>
</head>
<body>
<header>
<h1>Манипуляции с DOM</h1>
<h2>Методы <code>offset()</code> и <code>position()</code></h2>
</header>
<main>
<article>
<div id="box" class="square"></div>
</article>
</main>
<footer>
© <a href="https://anton.shevchuk.name/jquery-book/">jQuery for beginners</a>
</footer>
<aside>
<nav>
<a href="height.html" title="go back" rel="prev">Back</a>
<a href="index.html#20" title="back to Index" rel="index">Index</a>
<a href="#" title="reload" onclick="window.location.reload();return false">Reload</a>
<a href="data.html" title="go next" rel="next">Next</a>
</nav>
<hr/>
<code data-replace="#output"><em>// get offset: top</em>
$(<span>"#box"</span>).offset().top</code>
<button type="button">Run Code</button>
<code data-replace="#output"><em>// get offset: left</em>
$(<span>"#box"</span>).offset().left</code>
<button type="button">Run Code</button>
<code data-replace="#output"><em>// get relative position: top</em>
$(<span>"#box"</span>).position().top</code>
<button type="button">Run Code</button>
<code data-replace="#output"><em>// get relative position: left</em>
$(<span>"#box"</span>).position().left</code>
<button type="button">Run Code</button>
<code contenteditable="true"><em>// set offset</em>
$(<span>"#box"</span>)
.offset({ top: 200, left: 600 })</code>
<button type="button">Run Code</button>
</aside>
<aside id="output">
<h4>Output:</h4>
<hr/>
<code></code>
</aside>
</body>
</html>