I want to know if there is any way you can call and use what the overflow:hidden
has well hidden.
To clarify what I mean, in this example I would like to know that "This is hidden" is the hidden part of the div.
Is this even possible? How would you approach it?
I've tagged the question jQuery but of course whatever gets the job done is great, pure CSS or Javascript will do just fine.
Thanks in advance!
overflow: hiddenWith the hidden value, the overflow is clipped, and the rest of the content is hidden: You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.
To change this, set the min-width or min-height property.” This means that a flex item with a long word won't shrink below its minimum content size. To fix this, we can either use an overflow value other than visible , or we can set min-width: 0 on the flex item.
The rules for detecting overflow in a two's complement sum are simple: If the sum of two positive numbers yields a negative result, the sum has overflowed. If the sum of two negative numbers yields a positive result, the sum has overflowed. Otherwise, the sum has not overflowed.
Try this:
CSS:
.text{
outline:1px solid orange;
width:100px;
height:20px;
overflow:hidden;
}
HTML:
<div class="text">This is shown. This is hidden</div>
<div id="result"></div>
<div id="container" style="visibility:hidden;"></div>
JS:
$("<span />").text($(".text").text()).appendTo("#container");
$("#result").append("<span>"+$(".text").width()+"</span><br />");
$("#result").append("<span>"+$("#container span").width()+"</span><br />");
$("#result").append("<span>Overflow: "+ (($("#container span").width() > $(".text").width()) ? "yes" : "no")+"</span><br />");
Example
EDIT
Try this:
based on this plugin
New Example
CSS:
.text{
outline:1px solid orange;
width:100px;
height:20px;
overflow:hidden;
}
HTML:
<br/>
<br/>
<div class="text" id="test1">This is shown. This is hidden</div>
<div class="text" id="test2">No hidden</div>
<br/>
<br/>
<div id="result"></div>
JS:
(function($) {
$.fn.noOverflow = function(){
return this.each(function() {
var el = $(this);
var originalText = el.text();
var w = el.width();
var t = $(this.cloneNode(true)).hide().css({
'position': 'absolute',
'width': 'auto',
'overflow': 'visible',
'max-width': 'inherit'
});
el.after(t);
var text = originalText;
while(text.length > 0 && t.width() > el.width()){
text = text.substr(0, text.length - 1);
t.text(text + "");
}
el.text(t.text());
/*
var oldW = el.width();
setInterval(function(){
if(el.width() != oldW){
oldW = el.width();
el.html(originalText);
el.ellipsis();
}
}, 200);
*/
this["overflow_text"] = {
hasOverflow: originalText != el.text() ? true : false,
texOverflow: originalText.substr(el.text().length)
};
t.remove();
});
};
})(jQuery);
$("#test1").noOverflow();
$("#result").append("<span>Test 1</span><br />");
$("#result").append("<span>Has Overflow: "+ (($("#test1")[0].overflow_text.hasOverflow) ? "yes" : "no")+"</span><br />");
$("#result").append("<span>Text Overflow: "+ $("#test1")[0].overflow_text.texOverflow+"</span><br />");
$("#test2").noOverflow();
$("#result").append("<br /><span>Test 2</span><br />");
$("#result").append("<span>Has Overflow: "+ (($("#test2")[0].overflow_text.hasOverflow) ? "yes" : "no")+"</span><br />");
$("#result").append("<span>Text Overflow: "+ $("#test2")[0].overflow_text.texOverflow+"</span><br />");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With