zoukankan      html  css  js  c++  java
  • js实现长按显示全部内容

    js实现文字超出省略号显示时长按显示全部

    元素内容超出省略号显示时长按该元素,生成toast弹窗(id:toolkitContainer),以显示全部内容

    #toolkitContainer {
      max- 150px;
      position: absolute;
      z-index: 999;
      background-color: #f6f6f6;
      border-radius: 5px;
      color: #000;
      padding: 5px 15px;
      border: solid 1px #ddd;
      opacity: .95;
      font-size: 12px;
    }
    
    window.onload = () => {
    	initListener();
    	//调用
    	$('td').each(function() {
    	   if($(this).width() < $(this).text().length * 14) {
    	      $(this).addClass('toolkit');
    	   }
    	});
    };
    
    //字浮动显示逻辑
    var initListener = function() {
       $('body').on('touchstart', '.toolkit', function(e) {
          var toolkit = $('#toolkitContainer');
          var body = $('body');
          var _this = $(this);
    
          if(toolkit.length == 0) {
             toolkit = $('<div></div>').attr('id', 'toolkitContainer')
                .appendTo($('body'));
          }
    
          _this.on('touchend', function() {
             $('#toolkitContainer').remove();
    
             _this.off('touchend');
             _this.off('touchcancel');
          });
    
          _this.on('touchcancel', function() {
             $('#toolkitContainer').remove();
    
             _this.off('touchend');
             _this.off('touchcancel');
          });
    
          toolkit.html($(this).attr('tText') || $(this).html());
    
          if(!toolkit.html()) {
             return;
          }
    
          var tx = e.originalEvent.touches[0].pageX - toolkit.width() / 2;
          tx = tx < 0 ? 0 : tx;
          tx = tx + toolkit.width() > body.width() ? tx - toolkit.width() : tx;
          var ty = e.originalEvent.touches[0].pageY - toolkit.height() - 30;
          ty = ty < 0 ? 0 : ty;
    
          toolkit.css('top', ty + 'px');
          toolkit.css('left', tx + 'px');
          toolkit.css('opcaity', '0.2');
          toolkit.show();
          toolkit.animate({
             opcaity: 1
          }, 300);
       });
    };
    
  • 相关阅读:
    通过 VB5 创建 ActiveX DLL 文件并用 ASP 调用一例
    Autocad VBA初级教程
    自学资料第一集
    Linux虚拟化:10个不得不爱的理由
    EXCEL VBA编程的一些小结
    FAQ 工作薄及工作表
    很重要的EXCEL使用技巧
    Excel VBA编程的常用代码
    VBA生成一个CorelDraw工具栏
    支付宝,网银在线,快钱 3大支付接口的集成与对比,统合实现
  • 原文地址:https://www.cnblogs.com/aui-js/p/14047618.html
Copyright © 2011-2022 走看看