Vanilla [removed] Resize font-awesome to fit container

后端 未结 1 602
别跟我提以往
别跟我提以往 2020-12-11 11:44

I have been creating an audio player using vanilla JavaScript to manipulate the HTML element.

The player is of dynamic size, with all elem

相关标签:
1条回答
  • 2020-12-11 12:01

    Add the class .jcfResize to any elements containing font which should be resized.

    Add the following javascript code to the page/site:

    function jcfResizeText() {
        var elements  = document.getElementsByClassName('jcfResize');
        if (elements.length < 0) {
            return;
        }
        _len = elements.length;
        for (_i = 0; _i < _len; _i++) {
            var el = elements[_i];
            el.style.fontSize = "100%";
            for (var size = 100; el.scrollHeight > el.clientHeight; size -= 10) {
                el.style.fontSize = size + '%';
            }
        }
    }
    
    jcfResizeText();
    window.addEventListener('resize', jcfResizeText); 
    
    0 讨论(0)
提交回复
热议问题