// 结合脚本语言动态的控制元素在页面中出现的位置。
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>css11.html</title>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <style type="text/css">
- <!--
- div.show{
- position:absolute;
- top:10;
- left:200;
- visibility:visible;
- }
- div.hide{
- position:absolute;
- top:120;
- left:200;
- visibility:hidden;
- }
- -->
- </style>
- </head>
- <body>
- <div class="hide"> //将不显示
- <img src="smile.gif" alt="">
- </div>
- <div class="show">
- <img src="cry.gif" alt="">
- </div>
- </body>
- </html>
【注】div块标记,该标记可以将其内部的图片及文字作为一个整体,及分层进行控制,往往可以实现页面效果的局部改变。
##CSS中的cursor属性改变鼠标指针的形状。
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>css12.html</title>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <style type="text/css">
- <!--
- .hand{cursor:hand;} /*手形*/ //==》class属性值
- .crosshair{cursor:crosshair;} /*精确定位“+”字*/
- .move{cursor:move;} /*移动*/
- .e-resize{cursor:e-resize;} /*箭头朝右方*/
- .ne-resize{cursor:ne-resize;} /*箭头朝右上方*/
- .nw-resize{cursor:nw-resize;} /*箭头朝左上方*/
- .n-resize{cursor:n-resize;} /*箭头朝上方*/
- .se-resize{cursor:se-resize;} /*箭头朝右下方*/
- .s-resize{cursor:s-resize;} /*箭头朝下方*/
- .w-resize{cursor:w-resize;} /*箭头朝左方*/
- .text{cursor:text;} /*“I”字型*/
- .wait{cursor:wait;} /*等待*/
- .help{cursor:help;} /*帮助*/
- -->
- </style>
- </head>
- <body>
- <p class="hand">
- Give me a hand!(手形)
- </p>
- <p class="crosshair">
- Give me a crosshair(精确定位)!
- </p>
- <p class="move">
- Give me a Move(移动)!
- </p>
- <p class="e-resize">
- Give me a e-resize(箭头方向朝右)!
- </p>
- <p class="ne-resize">
- Give me a ne-resize(箭头方向朝右上)!
- </p>
- <p class="nw-resize">
- Give me a nw-resize(箭头方向朝左上)!
- </p>
- <p class="n-resize">
- Give me a n-resize(上)!
- </p>
- <p class="se-resize">
- Give me a se-resize(左下)!
- </p>
- <p class="s-resize">
- Give me a s-resize(下)!
- </p>
- <p class="w-resize">
- Give me a w-resize(左)!
- </p>
- <p class="text">
- Give me a text(文本)!
- </p>
- <p class="wait">
- Give me a wait(等待)!
- </p>
- <p class="help">
- Give me a help(帮助)!
- </p>
- </body>
- </html>
//-------css+javascript 脚本实现的动态交互效果(设置首页)-----
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>setHome.html</title>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <script language="JavaScript" type="text/javascript">
- function set()
- {
- sethome.style.behavior="url(#default#homepage)";
- sethome.setHomePage(http://www.google.com);
- }
- </script>
- </head>
- <body>
- <span id="sethome" οnclick="set()" style="CURSOR: hand"><br>将本站设置为首页</span>
- </body>
- </html>
//-----------进一步丰富鼠标的效果------------
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>movPic.html</title>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <style type="text/css">
- <!--
- #topdown{
- position:absolute;
- left:12;
- top:222;
- }
- -->
- </style>
- <script language="JavaScript" type="text/javascript">
- function move(x, y)
- {
- topdown.style.left = x;
- topdown.style.top = y;
- }
- </script>
- </head>
- <body onmousemove="move(event.x, event.y)"> /×事件驱动×/
- <div id="topdown"> /×id 样式修饰×/
- <img src="smile.gif" alt=""> /*层标记 div×/
- </div>
- </body>
- </html>
解释:使用层标记div将图片单独放在一层中,然后使用css层叠样式表定义了该图片的位置,再与onmouseover事件结合,追踪鼠标的位置(event.x 和event.y),并随时用鼠标的位置修改对应图片的位置。
效果:页面中显示一张始终跟着鼠标指针移动的笑脸。