var tips={};//tip collection, create an object for each element in the matching set , this object saves some required information
//The tip below has nothing to do with the one above. It saves a canvas object, and this canvas is shared
").append(tip);
div.appendTo(" body");
var cxt = tip[0].getContext("2d");
this.each(function(){
var $that=$(this);
var offset = $that.offset();
var setleft=offset.left;//Get the position relative to the page
var settop=offset.top;
var theTip={};
var title = $("
");
theTip.title=title;//There is one title for each element, save them in the tips array
var fontSize=16;
//var fontSize=parseInt(theTip.title.css("fontSize"));
title.css("opacity",0);//First hide the P of the title attribute of the element to be loaded by default
div.append (theTip.title);
titleString=$that.attr("title");//Get the title attribute
var titleStringLength=titleString.length;//Get the length of the title
$that.attr( "title","");
title.text(titleString);//The value of the element title is saved in the P just created
theTip.titleWidth= title.width();//After loading The width of P
theTip.that=$that;
if(this.id) {tips[this.id]=theTip;}
else{$that.addClass(Math.random() "" );tips[$that.attr("class")]=theTip;}//If there is an ID, use the ID as the key, if not, generate a random class as the key
if(theTip.titleWidth>250|| titleStringLength>(250/fontSize)){//If the title is too long, then wrap it
var rowLength=Math.sqrt(titleStringLength*(5/1))*fontSize;
toBreakWord( (rowLength* 1.3)/fontSize,theTip.title[0]);
theTip.title.css("width",rowLength);
}
else{theTip.title.css({"width":titleStringLength *fontSize 10});}//,whiteSpace:"nowrap"
$that.hover(
function(){
var theTip=null;
if(this.id){theTip= tips[this.id];}
else{theTip=tips[this.className];}//Get your own object in tips based on key
var title=theTip.title;
/*width High calculation*/
var height=title.height()*1.1 20;
var width=title.width()*1.1 20;
title.css({top:title.height()* 0.1*0.5 10 "px",left:width*0.1 2 "px"});
tip.css({height:height "px",width:width "px"});
var lingrad = cxt.createLinearGradient(0,0,0,150); //Linear gradient of canvas
lingrad.addColorStop(0, '#00ABEB');
lingrad.addColorStop(0.5, 'rgba(10, 150, 255, 0.9)');
cxt.strokeStyle=lingrad;
var radgrad = cxt.createRadialGradient(150,75,10,150,75,150); //Reflective gradient of canvas
radgrad.addColorStop(0, ' rgba(10, 150, 255, 0.3)');
radgrad.addColorStop(0.5, 'rgba(10, 150, 255, 0.3)');
radgrad.addColorStop(1, 'rgba(256,256,256, 0.5)');
cxt.lineJoin="round";//The shape of the angle when two lines form an angle
cxt.lineWidth=2;//Line width
cxt.clearRect(0, 0,300,150);//Clear the canvas, because the canvas is shared, you must clear the last thing
/*Draw the tip shape I want*/
cxt.beginPath();
cxt.moveTo( 30.5,5.5);
cxt.lineTo(285.5,5.5);
cxt.lineTo(285.5,135.5);
cxt.lineTo(75.5,135.5);
cxt.lineTo(2.5, 148.5);
cxt.lineTo(30.5,125.5);
cxt.lineTo(30.5,5.5);
cxt.stroke();
/*fill*/
cxt.fillStyle ="#fff";
cxt.fill();
cxt.fillStyle=radgrad;
cxt.fill();
for(var flagtip in tips)//Let the text of other tips Hide
{ flagtip=tips[flagtip];
if(flagtip==theTip){flagtip.title.css("opacity",1);}
else{
if(flagtip.title .css){flagtip.title.css("opacity",0);}
}
}
div.css({left:setleft $that.width() "px",top:settop -2*tip.height() "px",opacity:0,height:height,width:width});
div.stop();
div.animate({top:settop-tip.height () "px",opacity:1},500)
},
function(){
div.stop();
div.animate({top:settop-2*tip. height() "px",opacity:0},1000)
})//hover
})//each
}
})(jQuery)
$(function() {
$("div p").children().add("#Button1").polaTip();
})