następujące jQuery plugin będzie ostrzegać wynik.
CSS
#tempDiv{
height:10px;
overflow:hidden;
}
Aby ustalić przepełnienia szerokości,
(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);
Aby ustalić przelew w wysokości
(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/
Co rozumiesz przez "wykrywanie" dokładnie? Co chcesz zrobić w reakcji, pokazać pasek przewijania? –
Chcę zmienić rozmiar div na zawisie myszy, jeśli tekst się przepełnił, ale już to posortowałem, aby nie było częścią pytania. –
Podobne stare pytanie z doskonałą odpowiedzią: https://stackoverflow.com/a/143889/573057 – earcam