简体   繁体   English

宽度溢出Div时减小字体大小

[英]Decreasing Font Size When Width Overflows Div

I believe my question is unique because I am using a counter whose width can constantly increase, as opposed to the container width changing, which is what seems to usually be asked. 我认为我的问题很独特,因为我使用的计数器的宽度可以不断增加,而不是像通常要求的容器宽度变化那样。

My site is http://script-timer.com/ , and I am trying to decrease the font of the timer when it overflows its container div. 我的网站是http://script-timer.com/ ,并且在计时器溢出其容器div时,我试图减小计时器的字体。 Here is the javascript I am currently working on to accomplish this: 这是我目前正在努力实现的JavaScript:

$(document).ready(function() {
    while( $('#scriptTime').width() > $('#timer-container').width() ) {
        $('#scriptTime').css('font-size', (parseInt($('#scriptTime').css('font-size')) - 1) + "rem" );
    } 
});

This looks like right to me, but being as I am very much still learning, I am most likely missing something simple. 这对我来说似乎是正确的,但是由于我仍在学习中,所以我很可能会错过一些简单的东西。 Is there a better way to accomplish this? 有没有更好的方法可以做到这一点? Thank you for your help! 谢谢您的帮助!

Here is a link to the plugin: https://plugins.jquery.com/textfill/ And a link to the source: http://jquery-textfill.github.io/ 这是插件的链接: https : //plugins.jquery.com/textfill/和源的链接: http : //jquery-textfill.github.io/

or 要么

add this in css method 在css方法中添加

overflow: auto; 溢出:自动;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM