[英]jQuery Resize Line of text To Fit Div Width
我正在使用以下腳本來調整單行字符串的大小,以使其適合div框。
<script type="text/javascript">
$( '.test' ).css( 'font-size', 0 ).each(function ( i, box2 ) {
var width = $( box2 ).width()
var line = $( box2 ).wrapInner( '<span style="white-space:nowrap">' ).children()[ 0 ];
function changeFontSize( n ) {
$( box2 ).css( 'font-size', function ( i, val ) {
return parseInt( val, 10 ) + n; });
})
while ( $( line ).width() < width ) { changeFontSize( 1 ); }
changeFontSize( -1 );
$( box2 ).text( $( line ).text() );
});
</script>
該腳本可在Firefox,Chrome和Opera中完美運行。 但是,在IE中,如果用戶處於兼容模式,則會出錯並鎖定瀏覽器。 我對較舊的瀏覽器了解不足,無法知道我添加的內容不兼容。
任何幫助是極大的贊賞。
這格式錯誤,可能會在IE中中斷,其始終如此敏感。
<span style="white-space:nowrap">
應該
<span style="white-space:nowrap;">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.