A better Tooltip with jQuery

在国外的一个网站上看到了一份不错的jQuery 插件,主要是样式挺好的,于是转了过来方便以后需要是拿来用之.... 

预览一下:

 

文件主要文件及目录:

  • Images folder contains the following images:
  • – - tipTip.png – created in Step 2
  • – - tipMid.png – created in Step 2
  • – - tipBtm.png – created in Step 2
  • style.css – created in Step 3
  • jquery-1.3.1.min.js – download this here
  • jquery.betterTooltip.js – – created in Step 5

 三个图片切片位置为:

由于是PNG格式,IE支持不是很好,载入的时候边框会黑一下,然后才会用图片填充(我刚用IE8 也是这样)

看了别人的回复后说有个 ie_pngfix 的东东,以后再研究一下...

如果实在不行,我不用PNG还不行....O(∩_∩)O哈哈~ 

 

CSS 主要文件如下:

ExpandedBlockStart.gif 代码
.tip  {   
    width
:  212px ;   
    padding-top
:  37px ;   
    display
:  none ;   
    position
:  absolute ;   
    background
:  transparent url(images/tipTop.png) no-repeat top ; }   
  
.tipMid 
{ background :  transparent url(images/tipMid.png) repeat-y ;  padding :  0 25px 20px 25px ; }   
.tipBtm 
{ background :  transparent url(images/tipBtm.png) no-repeat bottombottom ;  height :  32px ; }   

 

 

jQeury:

ExpandedBlockStart.gif 代码
$.fn.betterTooltip  =   function (options){  
  
        
/*  Setup the options for the tooltip that can be 
           accessed from outside the plugin              
*/   
        
var  defaults  =  {  
            speed: 
200 ,  
            delay: 
300   
        };  
  
        
var  options  =  $.extend(defaults, options);  
  
        
/*  Create a function that builds the tooltip 
           markup. Then, prepend the tooltip to the body 
*/   
        getTip 
=   function () {  
            
var  tTip  =   
            
" <div class='tip'> "   +   
                
" <div class='tipMid'> "      +   
                
" </div> "   +   
                
" <div class='tipBtm'></div> "   +   
            
" </div> " ;  
            
return  tTip;  
        }  
        $(
" body " ).prepend(getTip());  
  
        
/*  Give each item with the class associated with 
           the plugin the ability to call the tooltip    
*/   
        $(
this ).each( function (){  
  
            
var  $ this   =  $( this );  
            
var  tip  =  $( ' .tip ' );  
            
var  tipInner  =  $( ' .tip .tipMid ' );  
  
            
var  tTitle  =  ( this .title);  
            
this .title  =   "" ;  
  
            
var  offset  =  $( this ).offset();  
            
var  tLeft  =  offset.left;  
            
var  tTop  =  offset.top;  
            
var  tWidth  =  $ this .width();  
            
var  tHeight  =  $ this .height();  
  
            
/*  Mouse over and out functions */   
            $
this .hover( function () {  
                tipInner.html(tTitle);  
                setTip(tTop, tLeft);  
                setTimer();  
            },  
            
function () {  
                stopTimer();  
                tip.hide();  
            }  
        );           
  
        
/*  Delay the fade-in animation of the tooltip  */   
        setTimer 
=   function () {  
            $
this .showTipTimer  =  setInterval( " showTip() " , defaults.delay);  
        }  
  
        stopTimer 
=   function () {  
            clearInterval($
this .showTipTimer);  
        }  
  
        
/*  Position the tooltip relative to the class 
           associated with the tooltip                
*/   
        setTip 
=   function (top, left){  
            
var  topOffset  =  tip.height();  
            
var  xTip  =  (left - 30 ) + " px " ;  
            
var  yTip  =  (top - topOffset - 60 ) + " px " ;  
            tip.css({
' top '  : yTip,  ' left '  : xTip});  
        }  
  
        
/*  This function stops the timer and creates the 
           fade-in animation                          
*/   
        showTip 
=   function (){  
            stopTimer();  
            tip.animate({
" top " " +=20px " " opacity " " toggle " }, defaults.speed);  
        }  
    });  
};  

 

 

示例代码:

  <html xmlns="http://www.w3.org/1999/xhtml"> 

< head >      
    
< link  href ="theme/style.css"  rel ="stylesheet"  type ="text/css"  media ="all"   />  
    
< script  type ="text/javascript"  src ="js/jquery-1.3.1.min.js" ></ script >  
    
< script  type ="text/javascript"  src ="js/jquery.betterTooltip.js" ></ script >  
    
< script  type ="text/javascript" >  
        $(document).ready(
function (){
            $(
' .tTip ' ).betterTooltip({speed:  150 , delay:  300 });
        });
    
</ script >  
    
    
</ head >  
< body >      
    
        
< div  class ="tTip"  title ="The letter T. " > What's the difference between here and there? </ div >  
      
         
< href ="#"  title ="http://flynn.cnblogs.com" > My Blog </ a >
</ body >  
</ html >

 

 

源文件下载:点击下载

Demo 地址: 浏览Demo

原文地址:点击浏览 

 

 

转载于:https://www.cnblogs.com/Flynn/archive/2010/06/02/1749747.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值