Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Позиционирование (https://javascript.ru/forum/jquery/31808-pozicionirovanie.html)

vyaceslav.kr 21.09.2012 14:00

Позиционирование
 
Привет!
Есть два DIV'a:
<div class="container">
    <div class="1"></div>
    <div class="2"></div>
</div>


Как узнать TOP между 1ым и 2ым DIV'ом ?

ksa 21.09.2012 14:52

Цитата:

Сообщение от vyaceslav.kr
Как узнать TOP между 1ым и 2ым DIV'ом ?

Это про расстояние между ними?
Тогда как вариант...

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="tmp.css" />
-->
<style type="text/css">
* {
	margin: 0;
	padding: 0;
}
.container {
	margin-top: 15px;
}
.d2 {
	background-color: red;
}
.d1 {
	margin-bottom: 10px;
	background-color: green;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
	var o1=$('.d1').offset();
	var h1=$('.d1').height();
	var o2=$('.d2').offset();
	alert(o2.top-o1.top-h1);
});
</script>
</head>
<body>
<table>
<div class="container">
    <div class="d1">1</div>
    <div class="d2">2</div>
</div>
</table>
</body>
</html>


Часовой пояс GMT +3, время: 22:17.