Hello,
I'm trying to calculate the center of a DIV element. But it doesn't seem to be working, I don't quite get what to do with the calculations.. Here's my code:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style type="text/css">
body {
background-color: #cccccc;
}
.rectangle {
width: 400px;
height: 100px;
border-style:solid;
border-width:1px;
margin-top: 300px;
margin-left: 500px;
}
.pointer {
width: 400px;
height: 100px;
border-style:solid;
border-width:1px;
margin-top: 200px;
margin-left: 50px;
}
</style>
<script>
$(document).ready(function() {
var w = $('.rectangle').width();
var h = $('.rectangle').height();
var x = w/2; // 200
var y = h/2; // 50
});
</script>
</head>
<body>
<div class="rectangle"></div>
<div class="pointer"></div>
</body>
Any ideas? Thanks =)