鼠标悬浮提示效果:
View Code
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"/> 5 <title> New Document </title> 6 <style type="text/css"> 7 body{ 8 padding:10px; 9 min-height:400px; 10 } 11 .tip-help-wrap{ 12 position:absolute; 13 margin:10px; 14 color: #F60; 15 width: 240px; 16 display:none; 17 } 18 .tip-help-content{ 19 padding:5px; 20 border:1px solid #99CFEB; 21 background:#F4FAFD; 22 -moz-border-radius:4px; 23 -webkit-border-radius:4px; 24 -khtml-border-radius:4px; 25 border-radius:4px; 26 min-height:36px; 27 } 28 .tip-direction{ 29 position:absolute; 30 height:19px; 31 } 32 .tip-direction span { 33 height: 19px; 34 width: 17px; 35 font-family: Simsun; 36 font-size: 16px; 37 line-height: 21px; 38 overflow: hidden; 39 position: absolute; 40 } 41 .tip-direction span.tip-corner-inner{ 42 color:#F4FAFD; 43 z-index:2; 44 } 45 .tip-direction span.tip-corner-outer{ 46 color:#99CFEB; 47 z-index:1; 48 } 49 .tip-direction-left-top{ 50 top:10px; 51 left:-7px; 52 width:8px; 53 overflow:hidden; 54 } 55 .tip-direction-left-top span.tip-corner-inner{ 56 left:1px; 57 } 58 59 60 .tip-direction-left-bottom{ 61 bottom:10px; 62 left:-7px; 63 width:8px; 64 overflow:hidden; 65 } 66 .tip-direction-left-bottom span.tip-corner-inner{ 67 left:1px; 68 } 69 70 .tip-direction-right-top{ 71 top:10px; 72 right:-9px; 73 width:17px; 74 } 75 .tip-direction-right-top span.tip-corner-inner{ 76 left:-1px; 77 } 78 79 .tip-direction-right-bottom{ 80 bottom:10px; 81 right:-9px; 82 width:17px; 83 } 84 .tip-direction-right-bottom span.tip-corner-inner{ 85 left:-1px; 86 } 87 88 .tip-direction-top-left{ 89 top:-10px; 90 left:10px; 91 width:17px; 92 } 93 .tip-direction-top-left span.tip-corner-inner{ 94 top:1px; 95 } 96 97 .tip-direction-top-right{ 98 top:-10px; 99 right:10px; 100 width:17px; 101 } 102 .tip-direction-top-right span.tip-corner-inner{ 103 top:1px; 104 } 105 106 .tip-direction-bottom-left{ 107 bottom:-9px; 108 left:10px; 109 width:17px; 110 } 111 .tip-direction-bottom-left span.tip-corner-inner{ 112 top:-1px; 113 } 114 115 .tip-direction-bottom-right{ 116 bottom:-9px; 117 right:10px; 118 width:17px; 119 } 120 .tip-direction-bottom-right span.tip-corner-inner{ 121 top:-1px; 122 } 123 124 .icon-help{ 125 display:inline-block; 126 cursor:pointer; 127 font-size:0; 128 line-height:0; 129 height:0; 130 overflow:hidden; 131 width:16px; 132 height:16px; 133 background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0y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1hXRoGkDAsqx+oAHDMDojkYiUUsqesXXZ1huXH5a35VE8eZeQbb1x2TO2LqWUMhKJSMMwOn1Ah6qqxDfSDMykcF2P6dVd3sxt0jX4le7hNeLraR5cKcV1PQZmUsQ30qiqCtCRCzSFQiGeWQLX9QB4MZ3Mplzg93EzXASQ1V/HBO3hEEBTLoCiKMwnVnD2CzKoCh6nSzvDqcI8nk8ls/p8Yg9FKQUgEyKu6+E4hxt03w4hkRjD33g1+5ODtRnkZt65Mujn8/JWVqguy2cuscvT0QSTqzuHGlcG/QghAPABI7Zt01wXwHG97Imt7dDz/gex7zuHeMf1aK4LYNs2wIgP6DNNk5qyfFrrS3Ccv1dpri3i8d1KWuuDWc5xPFrrS6gpy8c0TYC+Y0NDQxONjY13hBDl9643IHYdpuwtVlO/GF0QjMRS7KVdPE/SfrmMh9fOEo1GWVlZmdB1/X4mxBbLssaBwCNN48bFEl5OrhNb26G6NJ8L5Se5dSnI+dMnDn7llv+3TP+yzn8GAP33XT8VbT+FAAAAAElFTkSuQmCC'); 134 } 135 136 .one{ 137 position:absolute; 138 top:20px; 139 left:10px; 140 } 141 .two{ 142 position:absolute; 143 top:20px; 144 right:10px; 145 } 146 .three{ 147 position:absolute; 148 top:50px; 149 right:240px; 150 } 151 .four{ 152 position:absolute; 153 bottom:10px; 154 left:10px; 155 } 156 .five{ 157 position:absolute; 158 bottom:20px; 159 right:10px; 160 } 161 </style> 162 </head> 163 <body> 164 <span class="icon-help one">One One One One One One One One One One One One One One One One </span> 165 <span class="icon-help two">Two Two Two Two Two Two Two Two Two </span> 166 <span class="icon-help three">Three Three Three Three Three Three Three Three Three Three Three Three Three Three Three Three Three Three </span> 167 <span class="icon-help four">Four Four Four Four</span> 168 <span class="icon-help five">Five Five Five Five Five Five Five Five Five Five Five Five Five Five Five Five Five Five Five Five</span> 169 <div class="tip-help-wrap"> 170 <div class="tip-help-content"></div> 171 <div class="tip-direction"> 172 <span class="tip-corner-inner">◆</span> 173 <span class="tip-corner-outer">◆</span> 174 </div> 175 </div> 176 <script> 177 function getElementsByClassName(searchClass,node,tag){ 178 if(document.getElementsByClassName){ 179 return document.getElementsByClassName(searchClass); 180 } else { 181 var results=[]; 182 var eles = (node || document).getElementsByTagName((tag || "*")); 183 var i= eles.length; 184 var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); 185 while(--i>=0){ 186 if(pattern.test(eles[i].className)){ 187 results.push(eles[i]); 188 } 189 } 190 return results; 191 } 192 } 193 194 function getCSS(obj,prototype){ 195 if(obj.currentStyle){ 196 return obj.currentStyle[prototype]; 197 } else { 198 return document.defaultView.getComputedStyle(obj,null)[prototype]; 199 } 200 } 201 202 function bindTip(tipclassName){ 203 var iconHelps = getElementsByClassName(tipclassName); 204 for(var i=0,j=iconHelps.length;i<j;i++){ 205 iconHelps[i].onmouseover = function(){ 206 var pos=this.getBoundingClientRect(), 207 tip=getElementsByClassName("tip-help-wrap",document,"div")[0], 208 direction = getElementsByClassName("tip-direction",tip,"div")[0], 209 className = "tip-direction-left-top", 210 boxWidth = parseInt(getCSS(tip,"width")), 211 windowWidth = window.innerWidth || document.body.clientWidth, 212 windowHeight = window.innerHeight || document.body.clientHeight; 213 214 tip.style.left = "auto"; 215 tip.style.right = "auto"; 216 tip.style.top = "auto"; 217 tip.style.bottom = "auto"; 218 if(windowHeight - pos.bottom > 50){ 219 if(windowWidth-pos.left-30 < boxWidth){ 220 tip.style.left = (pos.left-boxWidth-20) + "px"; 221 tip.style.top = (pos.top - 20) + "px"; 222 className="tip-direction-right-top"; 223 } else { 224 tip.style.left = (pos.left + 15) + "px"; 225 tip.style.top = (pos.top - 20) + "px"; 226 } 227 } else { 228 if(windowWidth-pos.left-30 < boxWidth){ 229 tip.style.left = (pos.left-boxWidth-20) + "px"; 230 if(windowHeight >= pos.bottom){//IE678 document.body.clientHeight bug 231 tip.style.bottom = (windowHeight - pos.bottom - 20) + "px"; 232 className="tip-direction-right-bottom"; 233 } else { 234 tip.style.top = (pos.top - 25) + "px"; 235 className="tip-direction-right-top"; 236 } 237 } else { 238 tip.style.left = (pos.left + 15) + "px"; 239 if(windowHeight >= pos.bottom){//IE678 document.body.clientHeight bug 240 tip.style.bottom = (windowHeight - pos.bottom - 20) + "px"; 241 className="tip-direction-left-bottom"; 242 } else { 243 tip.style.top = (pos.top - 25) + "px"; 244 className="tip-direction-left-top"; 245 } 246 } 247 } 248 getElementsByClassName("tip-help-content",tip,"div")[0].innerHTML=this.innerHTML; 249 tip.style.display = "block"; 250 if(direction.className.indexOf(className) == -1){ 251 direction.className+=" "+className; 252 } 253 }; 254 iconHelps[i].onmouseout=function(){ 255 var tip=getElementsByClassName("tip-help-wrap",document,"div")[0], 256 direction=getElementsByClassName("tip-direction",tip,"div")[0]; 257 tip.style.display = "none"; 258 direction.className="tip-direction"; 259 }; 260 } 261 } 262 263 bindTip("icon-help"); 264 </script> 265 </body> 266 </html>
效果: