JSFiddle - React, Tailwind, and code Playground
HTML
<div class="arbitrary-background">
<div class="arbitrary-container">
<div class="arbitrary-row cf">
<div class="arbitrary-cell">
The quick brown fox jumped over the lazy dog.
</div>
<div class="arbitrary-cell jsDynamicOverflow">
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
</div>
</div>
</div>
</div>
CSS
.arbitrary-background {
background-color: #00FF00;
}
.arbitrary-container {
}
.arbitrary-row {
}
.arbitrary-cell {
float: left;
width: 50%;
overflow: hidden;
height: 100px;
}
.jsHasEllipsis {
position: relative;
}
.jsEllipsis {
display: none;
position: absolute;
bottom: 0px;
right: 0px;
line-height: inherit;
font-size: inherit;
/*background-color: #00FF00;*/
padding-left: 10px;
cursor: pointer;
}
.jsHasEllipsis>.jsEllipsis {
display: inline-block;
}
/* clearfix */
.cf:before,
.cf:after {
content: " ";
display: table;
}
.cf:after {
clear: both;
}
.cf {
*zoom: 1;
}
JavaScript
var $window = $(window);
var $jsDynamicOverflow = $('.jsDynamicOverflow');
$jsDynamicOverflow.each(function() {
var _this = this;
var $this = $(this);
var backgroundColor = false;
var $bgTarget = $this;
// determine background-color
while (!backgroundColor) {
var sThisBgColor = $bgTarget.css('background-color');
var bIsTransparent = sThisBgColor == 'rgba(0, 0, 0, 0)';
backgroundColor = !bIsTransparent ? sThisBgColor : backgroundColor;
if (($bgTarget.is('html')) && !backgroundColor) {
backgroundColor = '#FFFFFF';
}
else {
$bgTarget = $bgTarget.parent();
}
}
// dynamic ellipsis
//backgroundColor = '#FFFF00';
var sGradientStyle = 'background: -webkit-linear-gradient(left,rgba(0,0,0,0),'+backgroundColor+' 40%);background: -o-linear-gradient(right,rgba(0,0,0,0),'+backgroundColor+' 40%);background: -moz-linear-gradient(right,rgba(0,0,0,0),'+backgroundColor+' 40%);background: linear-gradient(to right, rgba(0,0,0,0), '+backgroundColor+' 40%);';
var $span = $('<span class="jsEllipsis" style="'+sGradientStyle+'">…</span>');
$span.appendTo($this);
var fWindowResize = function() {
// determine if ellipsis should be visible
var bShowEllipsis = (_this.offsetHeight < _this.scrollHeight || _this.offsetWidth < _this.scrollWidth);
console.log(bShowEllipsis + (new Date()).toString());
$this.toggleClass('jsHasEllipsis', bShowEllipsis);
};
var fShowOverflow = function() {
var iHeight = $this.height();
var iDelta = _this.scrollHeight - _this.offsetHeight;
//$this.height(iHeight + iDelta);
$this.removeClass('jsHasEllipsis');
// OR
$this.css('height', 'auto');
};
// wire events
$window.resize(fWindowResize);
// initial state
fWindowResize();
$span.click(fShowOverflow);
});