ऊपर एक छोटा सा कोड है, क्योंकि यह कंटेनर की चौड़ाई पाने के लिए है जिसे मैंने ऊँचा कंटेनर समायोजन के लिए संपादित किया है।
$.fn.adjustTextSize = function (set_max_size, min_size) {
min_size = min_size || 12; // if no value then set a default one
var string, height, line, initFontSize, returnFontSize, ratio;
return this.each(function() {
// Store the object
var $this = $(this);
var resizer = function() {
string = $this;
string.html('<span>' + string.html() + '</span>');
height = string.height();
line = $(string.children('span'));
initFontSize = parseInt(string.css('font-size'));
ratio = height/line.height();
returnFontSize = (initFontSize*ratio) ;
if (set_max_size && returnFontSize > initFontSize) {
returnFontSize = initFontSize;
}
if (min_size && returnFontSize < min_size) {
returnFontSize = min_size;
}
string.css('font-size',returnFontSize);
while (line.height() >= height) {
if (min_size && returnFontSize <= min_size) {
string.html(line.html());
return false;
}
string.css('font-size', --returnFontSize);
}
string.html(line.html());
}
// Call once to set.
resizer();
// Call on resize. Opera debounces their resize by default.
$(window).on('resize orientationchange', resizer);
});
};
आशा है कि यह उपयोगी
स्रोत
2014-02-21 18:51:11
[जावास्क्रिप्ट के संभावित डुप्लिकेट कि स्वचालित रूप से तत्व पर फ़ॉन्ट आकार सेट इतना है कि पाठ अतिप्रवाह नहीं करता होगा? (ऑटोफिट)] (http://stackoverflow.com/questions/1178651/javascript-that-automatically-sets-font-size-on-element-so-that-text-doesnt-ove) – Quentin
यह एक डुप्लिकेट प्रश्न है http://stackoverflow.com/questions/3840452/change-font-size-to-automatically-fit-divs-height-width – coder