jQCloud 如何使用 fontsize 属性 作为函数
jQCloud How to Use fontsize Property as Function
根据jQCloud的documentation,可以通过三种方式设置字体大小。
- 数组
- 对象
- 函数
我想知道如何使用函数设置字体大小。我是 jQCloud 的新手,找不到任何使用该函数方法的示例。
实际上我希望单词的字体大小能够响应。默认情况下,字体大小是基于所有分辨率或 windows 大小的 10 个步骤固定的。我想知道这种功能性方法是否有助于实现响应能力。
任何提示或解决方案将不胜感激。
从文档中可以看出:
A function taking the container width, the container height and a step number as parameters and returning a valid CSS font size
因此您可以提供一个接受这些参数和returns要使用的字体大小的函数。例如:
$('#keywords').jQCloud(words, {
fontSize: function(width, height, step) {
return (width / 2 * step) + 'px';
}
});
这很可能会给你大量的字体,但重点是让逻辑清晰。您可以轻松调整输出以满足您的需求
在@Rory 和@Twisty 的帮助下,通过一些小的调整,我能够通过如下定义函数来解决问题:
$element.jQCloud(word_list, {
fontSize: function (width, height, step) {
if (step == 1)
return width * 0.02 * step + 'px';
return width * 0.01 * step + 'px';
},
delayedMode: false,
autoResize: true,
height: $element.parent("div").height(),
width: $element.parent("div").width()
});
根据jQCloud的documentation,可以通过三种方式设置字体大小。
- 数组
- 对象
- 函数
我想知道如何使用函数设置字体大小。我是 jQCloud 的新手,找不到任何使用该函数方法的示例。
实际上我希望单词的字体大小能够响应。默认情况下,字体大小是基于所有分辨率或 windows 大小的 10 个步骤固定的。我想知道这种功能性方法是否有助于实现响应能力。
任何提示或解决方案将不胜感激。
从文档中可以看出:
A function taking the container width, the container height and a step number as parameters and returning a valid CSS font size
因此您可以提供一个接受这些参数和returns要使用的字体大小的函数。例如:
$('#keywords').jQCloud(words, {
fontSize: function(width, height, step) {
return (width / 2 * step) + 'px';
}
});
这很可能会给你大量的字体,但重点是让逻辑清晰。您可以轻松调整输出以满足您的需求
在@Rory 和@Twisty 的帮助下,通过一些小的调整,我能够通过如下定义函数来解决问题:
$element.jQCloud(word_list, {
fontSize: function (width, height, step) {
if (step == 1)
return width * 0.02 * step + 'px';
return width * 0.01 * step + 'px';
},
delayedMode: false,
autoResize: true,
height: $element.parent("div").height(),
width: $element.parent("div").width()
});