EverKB

Knowledge Base Ever

根據標籤的數值設置標籤雲中每個標籤字體大小的方法

2019-11-21 22:03:37

標籤: JavaScript, Tag, Tag Cloud, font-size, 標籤雲,字體大小

按百分比計算的公式是:size = (count - min) * (MAX_PERCENT - MIN_PERCENT) / (max - min) + MIN_PERCENT

按字體大小計算的公式是:size = (count / count_max) * (FONT_MAX - FONT_MIN) + FONT_MIN

假設標籤是HTML鏈接,$是jQuery對象,則代碼如下:

JavaScript
// JavaScript
var count_arr = [];
    $("a.tag").each(function(){
        var count = $(this).attr("count");
        count_arr.push(count);
    });
    var count_max = Math.max.apply(null, count_arr);
    $("a.tag").each( function (i, o) {
        var FONT_MAX = 3;
        var FONT_MIN = 1;
        var count = $(this).attr("count");
        var size = (count / count_max) * (FONT_MAX - FONT_MIN) + FONT_MIN;
        $(this).css( "font-size", size + "em");
    });

標籤

CentOS7 CentOS PHP Linux Python3 Python MySQL MariaDB YUM JavaScript mysql_native_password PHP7 CSS Redis MySQL8 caching_sha2_password HTML root Tag Cloud CodeIgniter font-size ss5 apache httpd dual network interfaces Laravel ShadowsocksR vertical-align CURLFille horiz-align node.js SUBDATE BarManager exec mb_substr PyCharm SOCKS5 Proxy Server WebStorm date add IntelliJIDEA PEAR remi Tag Chrome find src Apache du jQuery PHP5.5 Shadowsocks-Python V2Ray cURL hide nginx sub folder availability eth0 MariaDB10.4 PostgreSQL SOCKS5 Web Server date Install MongoDB pdo_sqlsrv register_shutdown_function Symfony File Upload mssql-tools sqlsrv Zend Framework ADDDATE DevExpress JetBrain php-fpm Shadowsocks-Libev unixODBC-devel height network interface string Aura error_get_last Port 80 SOCKS Web Development data INDENTIFIED BY password policy requirements Redis5 SVN Fedora Media Writer msodbcsql SQLAlchemy absolute Deepin jemalloc Shadowsocks toggle convert FuelPHP mysqlclient ss5.passwd at-symbol Error Control Operator margin PHPUnit Framework SOCKET vps daemon process IIS password sudoers center Fatal Errors MongoDB4 SQL Server 2017 WiFi .htaccess DATE_SUB Phalcon set_error_handler TestCase Compiling PHP frequency conflict ss5.conf apr Elasticsearch7.3 PHPUnit Slim Vincent Garreau daemon HTTP particles.js Sudo Failed to build these modules: _uuid MongoDB SQL Server width DATE_ADD ip command pg_bha.conf scrollbar Tcp BBR Compiling Apache Frameworks MySQL-python ss5-3.8.9 Apache2.4 Elasticsearch libpython3.7m.so.1.0 PHPStorm show VIM CURLOPT_POSTFIELDS NodeJs substr Bluetooth Failed to build these modules: _ctypes Minimal ISO SQL Date Funcitons Wi-Fi date sub INTERVAL PECL