HTML
CSS
JavaScript
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>笔下光年</title>
</head>
<body style="position:absolute">

<p>z-index 属性支持动画效果。</p>
<p><b>注意:</b>Internet Explorer 9 及更早 IE 版本不支持 CSS 动画。</p>

<p>逐步改变 "myBox" 的 z-index 属性 从 1 到 5:<p>
<div id="container">
  <div id="myBox">myBox</div>
  <div style="top:20px;left:20px;z-index:1;">z-index 1</div>
  <div style="top:40px;left:40px;z-index:2;">z-index 2</div>
  <div style="top:60px;left:60px;z-index:3;">z-index 3</div>				
  <div style="top:80px;left:80px;z-index:4;">z-index 4</div>						
</div>

</body>
</html>
CSS
div {position: absolute;}

#container div {
    background-color: lightblue;
    border: 1px solid #333333;
    width: 100px;
    height: 100px;
    opacity: 0.5;
}

div#myBox {
    opacity: 1;
    background-color: coral;
    z-index: 1;
    -webkit-animation: mymove 5s infinite linear; /* Chrome, Safari, Opera */
    animation: mymove 5s infinite linear;
}

/* Chrome, Safari, Opera */
@-webkit-keyframes mymove {
    50% {z-index: 5;}
}

/* Standard syntax */
@keyframes mymove {
    50% {z-index: 5;}
}
JavaScript