初级JavaScript学习教程(五)(2)
2008-02-23 07:58:58来源:互联网 阅读 ()
范例1:一个动态文字滚动的例子。
test5_1.htm
| <html> <head> <title></title> <script LANGUAGE="JavaScript"> with (top.window.location) {baseURL = href.substring (0,href.lastIndexOf ("/") 1)} total_toc_items = 0; current_overID = ""; last_overID = ""; browser = navigator.appName; version = parseInt(navigator.appVersion); client=null; loaded = 0; if (browser == "Netscape" && version >= 3) client = "ns3"; function toc_item (img_name,icon_col,width,height) { if (client =="ns3") { img_prefix = baseURL img_name; this.icon_col = icon_col; this.toc_img_off = new Image (width,height); this.toc_img_off.src = img_prefix "_off.gif"; this.toc_img_on = new Image (width,height); this.toc_img_on.src = img_prefix "_on.gif"; } } function new_toc_item (img_name,icon_row,width,height) { toc_item [img_name] = new toc_item (img_name,icon_row,width,height); } function toc_mouseover (itemID) { if (client =="ns3") { current_overID = itemID; if (current_overID != last_overID) { document [current_overID].src = toc_item [current_overID].toc_img_on.src; if (last_overID != "") { document.images [last_overID].src = toc_item[last_overID].toc_img_off.src; } last_overID = current_overID; } } } function toc_mouseout () { if (client =="ns3") { if (current_overID != "") { document.images [current_overID].src = toc_item [current_overID].toc_img_off.src; } current_overID = ""; last_overID = ""; } } new_toc_item ("1",2,120,20); <!-- Begin function bannerObject(p){ this.msg = MESSAGE this.out = " " this.pos = POSITION this.delay = DELAY this.i = 0 this.reset = clearMessage} function clearMessage(){ this.pos = POSITION} var POSITION = 50; var DELAY = 150; var MESSAGE = "这是一个动态JavaScript文字显示的例子"; var scroll = new bannerObject(); function scroller(){ scroll.out = " "; if(scroll.pos>0) for (scroll.i = 0; scroll.i < scroll.pos; scroll.i ) { scroll.out =" " ; } if (scroll.pos>= 0) scroll.out = scroll.msg else scroll.out = scroll.msg.substring(-scroll.pos,scroll.msg.length) document.noticeForm.notice.value = scroll.out scroll.out = " "; scroll.pos--; scroll.pos--; if (scroll.pos < -(scroll.msg.length)) { scroll.reset(); } setTimeout ('scroller()',scroll.delay);} </script> </head> <body onload="scroller()" bgcolor="#000000" link="#C0C0C0" vlink="#C0C0C0" alink="#008080" text="#C0C0C0"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="100%"><form NAME="noticeForm"> <p><input TYPE="text" name="notice" size="40" style="background-color: rgb(192,192,192)"></p> </form> </td> </tr> </table> </center></div> </body> </html> |
范例2:颜色变化的例子。
test5_2.htm
| <html> <head> <script> <!-- function makearray(n) { this.length = n; for(var i = 1; i <= n; i ) this[i] = 0; return this;} hexa = new makearray(16); for(var i = 0; i < 10; i ) hexa[i] = i; hexa[10]="a"; hexa[11]="b"; hexa[12]="c"; hexa[13]="d"; hexa[14]="e"; hexa[15]="f"; function hex(i) { if (i < 0) return "00"; else if (i > 255) return "ff"; else return "" hexa[Math.floor(i/16)] hexa[i];} function setbgColor(r, g, b) { var hr = hex(r); var hg = hex(g); var hb = hex(b); document.bgColor = "#" hr hg hb;} function fade(sr, sg, sb, er, eg, eb, step) { for(var i = 0; i <= step; i ) { setbgColor( Math.floor(sr * ((step-i)/step) er * (i/step)), Math.floor(sg * ((step-i)/step) eg * (i/step)), Math.floor(sb * ((step-i)/step) eb * (i/step))); }} function fadein() { fade(255,0,0,0,0,255,100); fade(0,0,255,0,255,0,100); fade(0,255,0, 0,0,0, 100);} fadein(); // --> </script> <body> </body> </html> |
本讲介绍了用户自行创建对象的方法, 用户可根据需要创建自己的对象。并介绍了JavaScript中建数组的方法。
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
