seguente plugin per jQuery avviserà il risultato.
CSS
#tempDiv{
height:10px;
overflow:hidden;
}
Per determinare trabocco nella larghezza,
(function($) {
$.fn.isOverflowWidth = function() {
return this.each(function() {
var el = $(this);
if (el.css("overflow") == "hidden") {
var text = el.html();
var t = $(this.cloneNode(true)).hide().css('position', 'absolute').css('overflow', 'visible').width('auto').height(el.height());
el.after(t);
function width() {
return t.width() > el.width();
};
alert(width());
}
});
};
})(jQuery);
Per determinare trabocco in altezza,
(function($) {
$.fn.isOverflowHeight = function() {
return this.each(function() {
var el = $(this);
if (el.css("overflow") == "hidden") {
var text = el.html();
var t = $(this.cloneNode(true)).hide().css('position', 'absolute').css('overflow', 'visible').height('auto').width(el.width());
el.after(t);
function height() {
return t.height() > el.height();
};
alert(height());
}
});
};
})(jQuery);
http://jsfiddle.net/C3hTV/
fonte
2011-08-21 14:49:07
Cosa intendi per "rilevare" esattamente? Cosa vuoi fare in reazione, mostrare una barra di scorrimento? –
Voglio ridimensionare div al passaggio del mouse se il testo trabocca ma l'ho già eliminato, quindi non faceva parte della domanda. –
Vecchia domanda simile con una grande risposta: https://stackoverflow.com/a/143889/573057 – earcam