Animating a horizontally and vertically centred DIV
Hi, i've been wrestling with this issue for the last hour. I can't seem to get this centred div to animate properly.
What it currently does:
A small div, (10x2px) expands to full 100% width and 100% height. However, it expands in the bottom right hand corner of the screen.
What I am trying to get it to do:
To expand equally in all four directions.
Please help me with this. Im new to jquery and would appreciate your help.
Code:
- <!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>Jquery</title>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
- <script type="text/javascript">
- $(function() {
-
- $('#smallscreen').css({
- "opacity": "1",
- "bottom": "50%",
- "right": "50%",
- "top": "50%",
- "left": "50%",
-
- });
-
- $('#smallscreen').animate({
- "opacity": "1",
- "width": "100%",
- "height": "100%"
- });
- });
- </script>
- <style type="text/css">
- .test { font-weight: bold; }
- .blue { color: blue; }
- .red { color: red; }
- #smallscreen {
- position:absolute;
- width:10px;
- height:2px;
- z-index:1;
- background-color: #FFF;
- text-align:center;
- }
- body {
- background-color: #000;
- height: 100%;
- text-align:center;
- }
- </style>
- </head>
- <body>
- <div id="smallscreen"></div>
- </body>
- </html>