You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
3.6 KiB

2 years ago
!function($){$.fn.sTips=function(options){var o=$.extend({},$.fn.sTips.defaults,options);0==$("#_sTips").length&&$("body").append("<div id='_sTips'></div>"),$("#_sTips").hide(),$("#_sTips").bind({mouseenter:function(){$("#_sTips").stop(!0).fadeTo(o.inTime,o.phy)},mouseleave:function(){$("#_sTips").fadeOut(o.outTime)}});var sTipsPosition=function(e){var s=$(e).offset(),x=s.left,y=s.top-$("#_sTips").outerHeight();"1"==o.position&&(x=s.left-$("#_sTips").outerWidth(),y=s.top-$("#_sTips").outerHeight()),"11"==o.position&&(x=s.left,y=s.top-$("#_sTips").outerHeight()),"12"==o.position&&(x=s.left-$("#_sTips").outerWidth(),y=s.top),"2"==o.position&&(x=s.left+$(e).outerWidth(),y=s.top-$("#_sTips").outerHeight()),"21"==o.position&&(x=s.left+$(e).outerWidth()-$("#_sTips").outerWidth(),y=s.top-$("#_sTips").outerHeight()),"22"==o.position&&(x=s.left+$(e).outerWidth(),y=s.top),"3"==o.position&&(x=s.left+$(e).outerWidth(),y=s.top+$(e).outerHeight()),"31"==o.position&&(x=s.left+$(e).outerWidth(),y=s.top+$(e).outerHeight()-$("#_sTips").outerHeight()),"32"==o.position&&(x=s.left+$(e).outerWidth()-$("#_sTips").outerWidth(),y=s.top+$(e).outerHeight()),"4"==o.position&&(x=s.left-$("#_sTips").outerWidth(),y=s.top+$(e).outerHeight()),"41"==o.position&&(x=s.left-$("#_sTips").outerWidth(),y=s.top+$(e).outerHeight()-$("#_sTips").outerHeight()),"42"==o.position&&(x=s.left,y=s.top+$(e).outerHeight()),$("#_sTips").css({left:x,top:y})};this.each((function(){var _this=this;if(this.alt&&(this.sTips=this.alt,$(this).removeAttr("alt")),this.title&&(this.sTips=this.title,$(this).removeAttr("title")),null!=this.sTips){var titlelength=this.sTips.indexOf("{||}");titlelength>0?(this.sTipsTop=this.sTips.substr(0,titlelength),this.sTipsBody=this.sTips.substr(titlelength+4,this.sTips.length)):this.sTipsBody=this.sTips,$(this).on({mousemove:function(e){if(0!=o.mouse){var x=e.pageX,y=e.pageY;1==o.mouse?(x-=o.mousez+$("#_sTips").outerWidth(),y-=o.mousez+$("#_sTips").outerHeight()):2==o.mouse?(x+=o.mousez,y-=o.mousez+$("#_sTips").outerHeight()):3==o.mouse?(x+=o.mousez,y+=o.mousez):4==o.mouse&&(x-=o.mousez+$("#_sTips").outerWidth(),y+=o.mousez),x+$("#_sTips").outerWidth()>=document.body.clientWidth&&(x=document.body.clientWidth-$("#_sTips").outerWidth()),y+$("#_sTips").outerHeight()>=document.body.clientHeight&&(y=document.body.clientHeight-$("#_sTips").outerHeight()),x<0&&(x=0),y<0&&(y=0),$("#_sTips").css({left:x,top:y})}},mouseenter:function(){if($("#_sTips").hide(),$("#_sTips").stop(),$("#_sTips").html(""),this.sTipsTop&&($("#_sTips").prepend("<div id='_sTips_Top' class='"+o.topCss+"'>"+this.sTipsTop+"</div>"),$("#_sTips_Top").addClass(o.topCss)),$("#_sTips").append("<div id='_sTips_body' class='"+o.bodyCss+"'></div>"),$("#_sTips").addClass(o.sTipsCss),$("#_sTips").css("z-index",99999999999),"ajax:"==this.sTipsBody.substr(0,5))$("#_sTips_body").html(o.ajaxloading),$.ajax({url:this.sTipsBody.substr(5,this.sTipsBody.length),dataType:"html",global:!1,error:function(xhr,error){"error"==error&&"off"!=o.ajaxerror&&($("#_sTips_body").html("AJAX错误"+xhr.statusText),sTipsPosition(_this))},success:function(shtml){$("#_sTips_body").html(shtml),sTipsPosition(_this)}});else if("fn:"==this.sTipsBody.substr(0,3)){var html=eval(this.sTipsBody.substr(3,this.sTipsBody.length));html&&$("#_sTips_body").html(html)}else $("#_sTips_body").html(this.sTipsBody);sTipsPosition(this),$("#_sTips").fadeTo(o.inTime,o.phy)},mouseleave:function(){$("#_sTips").fadeOut(o.outTime)}})}}))},$.fn.sTips.defaults={phy:1,inTime:200,outTime:200,sTipsCss:"sTips",topCss:"sTip-Top",bodyCss:"sTips-Body",ajaxError:"",ajaxLoading:"loading...",position:2,mousez:10,mouse:0}}(jQuery);