sau jQuery plugin sẽ báo kết quả.
CSS
#tempDiv{
height:10px;
overflow:hidden;
}
Để xác định tràn trong chiều rộng,
(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);
Để xác định tràn vào chiều cao,
(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/
Nguồn
2011-08-21 14:49:07
Bạn có ý nghĩa gì khi "phát hiện" chính xác? Bạn muốn làm gì trong phản ứng, hiển thị thanh cuộn? –
Tôi muốn thay đổi kích thước div trên di chuột nếu văn bản tràn nhưng tôi đã sắp xếp nó ra để nó không phải là một phần của câu hỏi. –
Câu hỏi cũ tương tự với câu trả lời tuyệt vời: https://stackoverflow.com/a/143889/573057 – earcam