這是我第一個jQuery插件。我可以得到一些指針嗎?它目前沒有工作......第一個jQuery插件:TagCloud
; (function($) {
$.fn.tagCloud = function(options) {
options = options || {};
var maxPercent = options['maxPercent'] || 150;
var minPercent = options['minPercent'] || 100;
var retrieveCount = options['retrieveCount'] || function(element) { return $(element).attr('rel'); };
var apply = options['apply'] || function(element, size) { $(element).attr('style', 'font-size:' + size + '%;'); };
var max = null;
var min = null;
var tagElements = this;
tagElements.each(function(element) {
count = retrieveCount(element);
max = (max == null || count > max ? count : max);
min = (min == null || min > count ? count : min);
});
var multiplier = (maxPercent - minPercent)/(max - min);
tagElements.each(function(element) {
count = retrieveCount(count);
size = (minPercent + (count - min) * multiplier);
apply(element, size);
});
}
})(jQuery);
用法:$('a.tag').tagCloud();
指針什麼? – 2009-12-18 05:21:14
我是否正確? – 2009-12-18 05:32:54
它不工作... – 2009-12-18 05:35:48