简体   繁体   English

jQuery Texfill不适用于具有相同选择器的所有元素

[英]jQuery Texfill not working on all elements with same selector

I'm trying to use jQuery Textfill to make an HTML list's contents fit their container. 我正在尝试使用jQuery Textfill使HTML列表的内容适合其容器。 However, when I initialize the plugin with the relevant options, the textfill plugin only "acts" on the first instance of the selector. 但是,当我使用相关选项初始化插件时,textfill插件仅在选择器的第一个实例上“起作用”。 Eg 例如

<div id='abc'>
    <ul>
        <li>foo</li>
        <li>bar</li>
    </ul>
</div>

<script type="text/javascript">
$('#abc').textfill({
    debug: true,
    maxFontPixels: 0,
    innerTag: "li"
});
</script>

Only "foo" gets resized. 只有“ foo”的大小可以调整。 Here's a jsfiddle 这是一个jsfiddle

Does anyone know if there's a way to overcome this? 有谁知道是否有办法克服这个问题? Have I missed a certain option? 我错过了某个选择吗?

This is by design. 这是设计使然。 According to $.textfill docs it will add :visible:first to whatever you put in innerTag 根据$ .textfill 文档 ,它将在您放入innerTag的内容中添加:visible:first

Check what happens when the first LI is hidden: http://jsfiddle.net/9VwV3/ 检查隐藏第一个LI时会发生什么: http : //jsfiddle.net/9VwV3/

<div id='abc'>
    <ul>
        <li style="display:none;">foo</li>
        <li>bar</li>
    </ul>
</div>

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

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