zoukankan      html  css  js  c++  java
  • 基于js原生封装的点击显示完整文字


    基于js原生封装的点击显示完整文字

    
    (function(window) {
    	var inner = '';
    	var showCont_s = function(ele) {
    		this.init.apply(this, arguments);
    	}
    	showCont_s.prototype = {
    		//初始化,显示
    		init : function(ele, dom) {
    			var els = ele.dom;
    			var h = els.offsetWidth, fh = els.innerText.length;
    			if (this.whether(h, fh)) {
    				return;
    			}
    			if (els.querySelector('p')) {
    				this.hiddCont_s(els)
    			} else {
    				inner = '<p>' + els.innerText + '</p>';
    				els.innerHTML = inner;
    				this.abs_rihgt(els, ele.w)
    			}
    		},
    		//是否点击
    		whether : function(h, fh) {
    			var h = h, fh = fh;
    			return Math.ceil(h / 14) > fh
    		},
    		//隐藏
    		hiddCont_s : function(els) {
    			var els = els;
    			var p = els.querySelector('p')
    			els.innerHTML = p.innerText;
    		},
    		//定位
    		abs_rihgt : function(els, w) {
    			var els = els, w = w;
    			p = els.querySelector('p'), distance = els.offsetLeft;
    			p.style.left = this.computed(distance, w, p.innerText.length*15) + 'px';
    		},
    		//计算
    		computed : function(d, w, p) {
    			var d = d, w = w, p = p;
    			var j = d + p - w;
    			var num;
    			if (j < 0) {
    				num = 0;
    			} else if (j > 0) {
    				num = w - p;
    			}
    			return num;
    		}
    	}
    	window.showCont_s = showCont_s;
    })(window)
    
    
  • 相关阅读:
    mac 终端常见指令
    git常见指令
    iOS8的autolayout和size class
    UIWindow详解
    操作系统Unix、Windows、Mac OS、Linux的故事
    iOS引用当前显示的UIAlertView
    Unexpected CFBundleExecutable Key
    《CODE》讲了什么?
    exit和return的区别
    php 登录注册api接口代码
  • 原文地址:https://www.cnblogs.com/lalalagq/p/10213477.html
Copyright © 2011-2022 走看看