0

親の幅を埋めるためにフォントサイズの幅を調整するスクリプトが必要です。その親div内にテキストを含むコンテナがいくつかあるかもしれません。それらは、等幅の余白で互いに間隔をあけて配置されます。

したがって、どういうわけか、フォントのサイズ変更を繰り返し、サイズを 1px ずつ増やし、すべてのスパンとそのスペーサーの新しい幅がparentContainer 内に収まるかどうかを確認する必要があります...

これが私がこれまでに得たものです。

<style>
    span {
        margin-right:20px
    }
</style>

<div id="parentContainer">
    <span>some text</span>
    <span>more text</span>
    <span>another text</span>
</div>

<script>
    $("#parentContainer span:last-child").css("margin-right","0");

    function adjustFonts() {
    var myText = $("span").length, // count text containers
        spacersWidth = (myText - 1) * 20, // margin on the right side 
        availWidth = $("myText").innerWidth(),
                defaultFontSize = 11;

    var fontSize = ???

    $("myText").css("font-size", fontSize +"px");

}

adjustFonts();

$(window).resize(function() {
    adjustFonts();
});
</script>

ここに画像の説明を入力

4

0 に答える 0