ch12-04.html 2.04 KB
Newer Older
O'Reilly Media, Inc.'s avatar
O'Reilly Media, Inc. committed
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Fly-Ins</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
div
{
        padding: 0 5px;
}
#nav
{
        background-color: #ccc;
        width: 100px;
        cursor: pointer;
}
#div1 
{ 
        background-color: #00f;
        color: #fff;
        font-size: larger;
        position: absolute;
        width: 400px;
        height: 200px;
        left: -410px;
        top: -400px;
        }
#div2 { 
        background-color: #ff0;
        color: #;
        font-size: larger;
        position: relative;
        width: 400px;
        height: 200px;
        left: -410px;
        top: -400px;
        z-index: 4;
        }
#div3 { 
        background-color: #f00;
        color: #fff;
        font-size: larger;
        position: fixed;
        width: 400px;
        height: 200px;
        left: -410px;
        top: -400px;
        }
</style>
<script type="text/javascript">
//<![CDATA[

// global placeholders
var slides = ["div1","div2","div3"];
var x = 0;
var y = 0;
var currentSlide = 0;

window.onload=function () {
   document.getElementById("nav").onclick=nextSlide;
}

function nextSlide() {
   setTimeout("moveBlock()",1000);
}

function moveBlock() {
   x+=20;
   y+=20;
   var obj = document.getElementById(slides[currentSlide]);
   obj.style.top = x + "px";
   obj.style.left = y + "px";
   if (x < (100 + currentSlide * 60)) {
       setTimeout("moveBlock()", 100);
   } else {
      currentSlide++;
      x = 0; y = 0;
   }

   if (currentSlide >= slides.length) {
     document.getElementById("nav").onclick=null;
   }
}
//]]>
</script>
</head>
<body>
<div id="nav">
<p>Next slide</p>
</div>
<div id="div1">
<p>Blue block that is absolutely positioned.</p>
</div>
<div id="div2">
<p>Yellow block that is relatively positioned, and given a z-index of 4.</p>
</div>
<div id="div3">
<p>Red block that has fixed positioning.</p>
</div>
</body>
</html>