siguiente plugin de jQuery alertará al resultado.
CSS
#tempDiv{
height:10px;
overflow:hidden;
}
Para determinar desbordamiento en el ancho,
(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);
Para determinar desbordamiento en la altura,
(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/
¿Qué quiere decir con "detectar" exactamente? ¿Qué quieres hacer en reacción, mostrar una barra de desplazamiento? –
Quiero cambiar el tamaño de div en el mouse si el texto se desborda pero ya lo resolví, por lo que no era parte de la pregunta. –
Pregunta antigua similar con gran respuesta: https://stackoverflow.com/a/143889/573057 – earcam