// 结合脚本语言动态的控制元素在页面中出现的位置。
- <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
- <html>
- <head>
- <title>css11.html</title>
- <metahttp-equiv="content-type"content="text/html;charset=UTF-8">
- <styletype="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>
- <divclass="hide"> //将不显示
- <imgsrc="smile.gif"alt="">
- </div>
- <divclass="show">
- <imgsrc="cry.gif"alt="">
- </div>
- </body>
- </html>
【注】div块标记,该标记可以将其内部的图片及文字作为一个整体,及分层进行控制,往往可以实现页面效果的局部改变。
##CSS中的cursor属性改变鼠标指针的形状。
- <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
- <html>
- <head>
- <title>css12.html</title>
- <metahttp-equiv="content-type"content="text/html;charset=UTF-8">
- <styletype="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>
- <pclass="hand">
- Givemeahand!(手形)
- </p>
- <pclass="crosshair">
- Givemeacrosshair(精确定位)!
- </p>
- <pclass="move">
- GivemeaMove(移动)!
- </p>
- <pclass="e-resize">
- Givemeae-resize(箭头方向朝右)!
- </p>
- <pclass="ne-resize">
- Givemeane-resize(箭头方向朝右上)!
- </p>
- <pclass="nw-resize">
- Givemeanw-resize(箭头方向朝左上)!
- </p>
- <pclass="n-resize">
- Givemean-resize(上)!
- </p>
- <pclass="se-resize">
- Givemease-resize(左下)!
- </p>
- <pclass="s-resize">
- Givemeas-resize(下)!
- </p>
- <pclass="w-resize">
- Givemeaw-resize(左)!
- </p>
- <pclass="text">
- Givemeatext(文本)!
- </p>
- <pclass="wait">
- Givemeawait(等待)!
- </p>
- <pclass="help">
- Givemeahelp(帮助)!
- </p>
- </body>
- </html>
//-------css+javascript 脚本实现的动态交互效果(设置首页)-----
- <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
- <html>
- <head>
- <title>setHome.html</title>
- <metahttp-equiv="content-type"content="text/html;charset=UTF-8">
- <scriptlanguage="JavaScript"type="text/javascript">
- functionset()
- {
- sethome.style.behavior="url(#default#homepage)";
- sethome.setHomePage(http://www.google.com);
- }
- </script>
- </head>
- <body>
- <spanid="sethome"οnclick="set()"style="CURSOR:hand"><br>将本站设置为首页</span>
- </body>
- </html>
//-----------进一步丰富鼠标的效果------------
- <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
- <html>
- <head>
- <title>movPic.html</title>
- <metahttp-equiv="content-type"content="text/html;charset=UTF-8">
- <styletype="text/css">
- <!--
- #topdown{
- position:absolute;
- left:12;
- top:222;
- }
- -->
- </style>
- <scriptlanguage="JavaScript"type="text/javascript">
- functionmove(x,y)
- {
- topdown.style.left=x;
- topdown.style.top=y;
- }
- </script>
- </head>
- <bodyonmousemove="move(event.x,event.y)"> /×事件驱动×/
- <divid="topdown"> /×id 样式修饰×/
- <imgsrc="smile.gif"alt=""> /*层标记 div×/
- </div>
- </body>
- </html>
解释:使用层标记div将图片单独放在一层中,然后使用css层叠样式表定义了该图片的位置,再与onmouseover事件结合,追踪鼠标的位置(event.x 和event.y),并随时用鼠标的位置修改对应图片的位置。
效果:页面中显示一张始终跟着鼠标指针移动的笑脸。