鼠标移上去显示全部内容

引入js文件 

 


(function($){
   $.fn.toolTip = function(options) {
      
      //Providing plugin defaults 
      
      var defaults = {
         background: '#1e2227',
         color: '#fff',
         opacity: '0.8'
      },
      
       options = $.extend(defaults, options);
        
        // Always return the jQuery object to allow for chainability. 
        
       return this.each(function() {
         var elem = $(this);
         
         //grab the title attribute
         
       var title = elem.attr('title');
       
      //only show the tooltip when the title is not empty    
               
         if(title != '') {
            
            //creating the tooltip div
            
         var tooltip = $('<div id="tooltip" />');
         
         //Remove the title attribute's to avoid the native tooltip from the browser
            elem.attr('title','');
            
            // mouse over
            
            elem.hover(function(e) {
               tooltip.hide().appendTo('body')
                 .html(title)
                 .hide()
                 .css({
                  'background-color' : options.background,
                  'color' : options.color,
                  'opacity' : options.opacity,
                })
                 .fadeIn(500);
              
            },
            
            // mouse out
            
             function() {
               tooltip.remove(); //remove the tooltip
            });    
         }
         
         //mouse move the tooltip will follow the cursor
         //get X & Y position of the cursor
         elem.mouseenter(function(e) {
            if(e.target.innerHTML){
                    tooltip.css({
                        top: e.pageY + 10,
                        left: e.pageX + 20,
                    });
            }

         });
         
        });
        
   }
})(jQuery);
复制代码

css样式

css
/*鼠标移上title弹出框*/
/*title弹出框*/
//id名不用定义
#tooltip {
    border: 1px solid #444;
    font-size: 14px;
    max-width: 205px;
    padding:1em;
    position: absolute;
    z-index:2500;
    text-shadow:none;
    border-radius: 6px;
    -moz-border-radius: 6px;
    -webkit-border-radius: 6px;
    word-break: break-all;
}复制代码

html写法

//desc后台取来的数据,
<td class='tooltip' title='"+json.data[i].desc+"'>" +tailorContent(json.data[i].desc,15)+"</td>//js代码
$(".tooltip").toolTip();

复制代码


转载于:https://juejin.im/post/5b3de4fee51d4519226f20d5

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值