我偶然发现了这个非常有用的jQuery脚本,它为文本块添加了CSS内联背景。它工作得很好,但是当我通过CodeKit / JSHint运行时,我得到以下警告:
var options = $.extend(defaults, options);
'options' is already defined. — column 18
这是jQuery代码,它可以工作 - 我只是好奇为什么CodeKit / JSHint会显示这个警告?
/*!
* jQuery Typographic Background Plugin
* http://owenmelbourne.com
*
* Copyright 2012, Owen Melbourne || Selesti Ltd
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://www.opensource.org/licenses/mit-license.php
* http://www.opensource.org/licenses/GPL-2.0
*/
(function($){
$.fn.typographicbg = function(options) {
var defaults = {
padding: '5px',
};
var options = $.extend(defaults, options);
return this.each(function() {
var selector = $(this);
var padding = options.padding;
$(selector).each(function(){
// Wrapping Words in Spans for padding application
var string = $(this).text().split(' ');
var word = $(this);
$(this).text('');
$.each(string, function(){
word.append('<span>'+this+' </span>');
});
$(this).find('span').css({'padding-top': padding, 'padding-bottom': padding});
$(this).find('span:first-child').css('padding-left', padding);
$(this).find('span:last-child').css('padding-right', padding);
var startingheight = $(this).find('span').position().top;
$(this).find('span').each(function(){
var thisheight = $(this).position().top;
//Apply the padding to new lines and previous
if (thisheight > startingheight) {
$(this).attr('data-ypos','height is: '+thisheight);
startingheight = thisheight;
$(this).css('padding-left', padding);
$(this).prev().css('padding-right', padding);
}
});
});
});
};
})(jQuery);
/* End Plugin Code */
// Run the plugin on .news-caption
$(function(){
$('.news-caption').typographicbg({padding: '5px'});
});
这是原始JSfiddle的链接 http://jsfiddle.net/OwenMelbz/rd8Qc/