开发者

Change jquery plugin from word counting to character plugin?

I'm trying to modify this plugin so that is counts characters rather than words.

$(function(){

    var $quote = $(".post p:first");

    var $numWords = $quote.text().split(" ").length;

    if (($numWords >= 1) && ($numWords < 10)) {
        $quote.css("font-size", "36px");
    }
    else if (($numWords >= 10) && ($numWords < 20)) {
        $quote.css("font-size", "32px");
    }
    else if (($numWords >= 20) && ($numWords < 30)) {
        $quote.css("font-size", "28px");
    }
    else if (($numWords >= 30) && ($numWords < 40)) {
        $quote开发者_JAVA百科.css("font-size", "24px");
    }
    else {
        $quote.css("font-size", "20px");
    }    

});

Here's the original post on the plugin: http://css-tricks.com/set-font-size-based-on-word-count/

Thanks!


This: $quote.text().split(" ").length

should be: $quote.text().length.

split(" ") divides the text by spaces, giving you the words. By removing this part, you count characters instead of words.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜