我的菜单

  1 document.onmouseover=showmune;
2 var sPop = null;
3 document.write('<style type=text/css>');
4 document.write('');
5 document.write('.PopText { font-family: Tahoma, 宋体; color: #000000; background-color: #66FF33; border: 1px #000000 dashed; font-size: 12px; line-height: 14px; padding: 4px; visibility: hidden; filter: Alpha(Opacity=0)}');
6 document.write('</style>');
7 document.write('<div id="popLayer" style="position:absolute;z-index:1000;filter:revealtrans(duration=.5,transition=12) revealTrans(duration=1,transition=23) alpha(opacity=90,enabled=100)"></div>');
8 function showmune(){
9 //显示菜单
10 var o = event.srcElement;
11 var temp_t = o.title;
12 var temp_a = o.alt;
13 var str_len = 0;
14 var i = 0;
15
16 if(o.alt!=null && o.alt!=""){ o.pop=o.alt;o.alt="";}
17   if(o.title!=null && o.title!=""){ o.pop=o.title;o.title="";}
18 if(o.pop){
19 o.pop=o.pop.replace(/(\\n)/g,"<br>");
20 /*
21 var temp = o.pop.split("<br>");
22 while(i < temp.length){
23 //str_len = str_len < x_str_len(temp[i]) ? x_str_len(temp[i]) : str_len; //自动
24 ++i;
25 }
26 */
27 str_len = 34; //固定长度
28 }
29 if(o.pop!=sPop){
30 sPop = o.pop;
31   if(sPop==null || sPop==""){
32     popLayer.filters[0].apply();
33     popLayer.style.visibility="hidden"; 
34     popLayer.filters[0].play();
35     popLayer.style.width="";
36   }else{
37     if(o.dyclass!=null) popStyle=o.dyclass;
38     else popStyle="PopText";
39   popLayer.filters[0].apply();
40 if(o.pop.substring(0,4) != "ylhx"){
41 o.title = temp_t;
42 o.alt = temp_a;
43     popLayer.style.visibility="hidden";
44 }else{
45 sPop = o.pop.substring(4,o.pop.length);
46 popLayer.style.visibility="visible";
47 }
48     popLayer.filters[0].play();
49     showit(str_len,i);
50   }
51 }
52
53 }
54 function showit(str_len,i){
55 var t_ary = new Array(new Array('<tr bgcolor="#00C80B" align="left"><td><font style="font-size: 11px; color: #FFFFFF">↖【叶绿辉香】-http://www.91ylhx.cn</font></td></tr>',
56 '<tr bgcolor="#00C80B" align="left"><td><font style="font-size: 11px; color: #FFFFFF">↙【叶绿辉香】-http://www.91ylhx.cn</font></td></tr>'),new Array(
57 '<tr bgcolor="#00C80B" align="right"><td><font style="font-size: 11px; color: #FFFFFF">【叶绿辉香】-http://www.91ylhx.cn↗</font></td></tr>',
58 '<tr bgcolor="#00C80B" align="right"><td><font style="font-size: 11px; color: #FFFFFF">【叶绿辉香】-http://www.91ylhx.cn↘</font></td></tr>')
59 );
60 var t_i1 = 0;
61 var t_i2 = 0;
62 //设定宽度和高度
63 var temp = parseInt((str_len*5+10) < 220 ? 220 :(str_len*5+10),10);
64 var X_width = parseInt((temp > 500 ? 500 : temp),10);
65 var X_height = parseInt((i+2)*20,10);
66
67 var H_left = parseInt(event.clientX,10);
68 var H_top = parseInt(event.clientY,10);
69 var bodyW = parseInt(get_wh()[0],10);
70 var bodyH = parseInt(get_wh()[1],10);
71 var ti = 10;
72 popLayer.style.left = ((H_left + X_width + ti > bodyW) ? (H_left - X_width - ti) : H_left)+document.documentElement.scrollLeft;
73 popLayer.style.top = ((H_top + X_height + ti > bodyH) ? (H_top - X_height - ti) : H_top)+document.documentElement.scrollTop;
74 t_i1 = (H_left + X_width + ti > bodyW) ? 1 : 0;
75 t_i2 = (H_top + X_height + ti > bodyH) ? 1 : 0;
76 popLayer.className=popStyle;
77 popLayer.innerHTML='<table width="'+X_width+'" width="'+X_height+'" border="0">'+((H_top + X_height + ti > bodyH) ? '<tr><td>'+sPop+'</td></tr>'+t_ary[t_i1][t_i2] : t_ary[t_i1][t_i2]+'<tr><td>'+sPop+'</td></tr>')+'</table>';
78
79 if(popLayer.offsetWidth > 500){ popLayer.style.width = 500;}
80 }
81 function get_wh(){
82 var winWidth = 0,winHeight = 0;
83 //获取窗口宽度
84 if(window.innerWidth){
85 winWidth = window.innerWidth;
86 }else if((document.body) && (document.body.clientWidth)){
87 winWidth = document.body.clientWidth;
88 }
89 //获取窗口高度
90 if(window.innerHeight){
91 winHeight = window.innerHeight;
92 }else if((document.body) && (document.body.clientHeight)){
93 winHeight = document.body.clientHeight;
94 }
95 //通过深入Document内部对body进行检测,获取窗口大小
96 if(document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth){
97 winHeight = document.documentElement.clientHeight;
98 winWidth = document.documentElement.clientWidth;
99 }
100 return new Array(winWidth,winHeight);
101 }
102 function x_str_len(str){ //获得字符串的长度
103 return str.replace(/[^\x00-\xff]/g, "xx").length;
104 }
105 function sub_str(str,start,len,flag){
106 //截取中文/英文字符串
107 if(len < 1) return "";
108 var xtmep = "";
109 var str_len = x_str_len(str);
110 var str_array = str.split("");
111 var num = 0;
112 var temp = str.replace(/[^\x00-\xff]/g, "xx").split("");
113 var i = 0;
114 var start1 = 0;
115 while(i < temp.length){
116 if(temp[i] == "x") ++i;
117 ++i;
118 if(start < i) break;
119 ++start1;
120 }
121 for(;start1 < str_array.length;start1++){
122 if(num >= len) break;
123 num += x_str_len(str_array[start1]);
124 xtmep += str_array[start1];
125 }
126 if(flag != "N" && ((flag == "Y" && start+len < str_len) || flag == "YY")){ xtmep += "...";}
127 return xtmep;
128 }

 

posted @ 2012-01-17 16:23  祥辉  阅读(194)  评论(0编辑  收藏  举报