返回列表 发帖

[JavaScript] 鼠标悬停提示效果的制作

鼠标悬停提示效果:



鼠标悬停提示效果代码(将以下代码中网站信息改为需要内容并存为 mouse.js 文件,放入到“js”文件夹中,也可以添加在“自定义标签”中调用):

var pltspop=null;
var pltsoffsetx = 10;
var pltsoffsety = 15;
var pltspopbg="#ffff00";
var pltspopfg="#111111";
var pltstitle="";
document.write('<div id=pltstiplayer style="display: none;position: absolute; z-index:10001"></div>');
function pltsinits()
{
    document.onmouseover   = plts;
    document.onmousemove = movetomouseloc;
}
function plts()
{  var o=event.srcelement;
    if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
    if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
    pltspop=o.dypop;
    if(pltspop!=null&&pltspop!=""&&typeof(pltspop)!="undefined")
    {
pltstiplayer.style.left=-1000;
pltstiplayer.style.display='';
var msg=pltspop.replace(/\n/g,"<br>");
msg=msg.replace(/\0x13/g,"<br>");
var re=/\{(.[^\{]*)\}/ig;
if(!re.test(msg))pltstitle=" 动易爱好者——动易模板 ";
else{
   re=/\{(.[^\{]*)\}(.*)/ig;
     pltstitle=msg.replace(re,"$1")+" ";
   re=/\{(.[^\{]*)\}/ig;
   msg=msg.replace(re,"");
   msg=msg.replace("<br>","");}
   var attr=(document.location.tostring().tolowercase().indexof("list.asp")>0?"nowrap":"");
        var content =
       '<table style="filter:alpha(opacity=90) shadow(color=#ae886f,direction=150);" id=tooltiptalbe border=0><tr><td width="100%"><table class=selet_bg cellspacing="0" cellpadding="0" style="width:100%" style="font size:11px;">'+
       '<tr id=pltspoptop><th height=12 valign=bottom class=header><p id=topleft align=left>╥'+pltstitle+'</p><p id=topright align=right style="display:none">'+pltstitle+'╦</font></th></tr>'+
       '<tr><td "+attr+" class=f_one style="padding-left:10px;padding-right:10px;padding-top: 4px;padding-bottom:4px;line-height:135%">'+msg+'</td></tr>'+
       '<tr id=pltspopbot style="display:none"><th height=12 valign=bottom class=header><p id=botleft align=left>╨'+pltstitle+'</p><p id=botright align=right style="display:none">'+pltstitle+'╧</font></th></tr>'+
       '</table></td></tr></table>';
        pltstiplayer.innerhtml=content;
        tooltiptalbe.style.width=math.min(pltstiplayer.clientwidth,document.body.clientwidth/2.2);
        movetomouseloc();
        return true;
       }
    else
    {
     pltstiplayer.innerhtml='';
       pltstiplayer.style.display='none';
        return true;
    }
}


function movetomouseloc()
{
if(pltstiplayer.innerhtml=='')return true;
var mousex=event.x;
var mousey=event.y;
//window.status=event.y;
var popheight=pltstiplayer.clientheight;
var popwidth=pltstiplayer.clientwidth;
if(mousey+pltsoffsety+popheight>document.body.clientheight)
{
    poptopadjust=-popheight-pltsoffsety*1.5;
    pltspoptop.style.display="none";
    pltspopbot.style.display="";
}
  else
{
     poptopadjust=0;
    pltspoptop.style.display="";
    pltspopbot.style.display="none";
}
if(mousex+pltsoffsetx+popwidth>document.body.clientwidth)
{
  popleftadjust=-popwidth-pltsoffsetx*2;
  topleft.style.display="none";
  botleft.style.display="none";
  topright.style.display="";
  botright.style.display="";
}
else
{
  popleftadjust=0;
  topleft.style.display="";
  botleft.style.display="";
  topright.style.display="none";
  botright.style.display="none";
}
pltstiplayer.style.left=mousex+pltsoffsetx+document.body.scrollleft+popleftadjust;
pltstiplayer.style.top=mousey+pltsoffsety+document.body.scrolltop+poptopadjust;
   return true;
}
pltsinits();


 

在网站css风格管理里加入以下内容:

/* --增加鼠标效应的css定义开始-- */
.header
{
font-family: times new roman, tahoma, verdana;
font-size: 12px;
color: #173f7c;
font-weight: thick;
background-color: #9fbfed;
}
.selet_bg
{
background-color: #9fbfed;
}
.f_one
{
background-color: #9fbfed;
border: #ffffff 1px solid;
}
 

在需要调用的页面里加入<script language=javascript src="/js/mouse.js"></script>

或者在需要调用的页面里加入自定义标签即可。具体演示效果见本站各页面。
欢迎光临:逐梦论坛

返回列表

Powered by Discuz! 7.2   论坛QQ群:逐梦论坛群

© 2001-2021 Comsenz Inc. 鲁公网安备 37120302000001号