我正在尝试开发一个骑行图片滑块,并对我正在参考的开发文档有个疑问。没有选择器的JQuery?
JQuery函数实际上并没有调用选择器,我不确定如何读取它。
$.fn.cycle = function(options, arg2) {
var o = { s: this.selector, c: this.context };
上面的脚本在我的javascript文档中,下面的方法是在我的HTML文档中调用上面的脚本。
$(document).ready(function() {
$('.headline').cycle({
fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle,
cleartypeNoBg:true
});
.headline是一个在HTML文档中定义的类。我很困惑,因为它有一个选择器,而$ .fn.cycle没有。
.headline是否将值传递给.fn?如果是这样,它是如何传递给变量的那部分?
如果希望看到完整的jQuery函数它是在这里:
$.fn.cycle = function(options, arg2) {
var o = { s: this.selector, c: this.context };
// in 1.3+ we can fix mistakes with the ready state
if (this.length === 0 && options != 'stop') {
if (!$.isReady && o.s) {
log('DOM not ready, queuing slideshow');
$(function() {
$(o.s,o.c).cycle(options,arg2);
});
return this;
}
// is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
return this;
}
// iterate the matched nodeset
return this.each(function() {
var opts = handleArguments(this, options, arg2);
if (opts === false)
return;
opts.updateActivePagerLink = opts.updateActivePagerLink || $.fn.cycle.updateActivePagerLink;
// stop existing slideshow for this container (if there is one)
if (this.cycleTimeout)
clearTimeout(this.cycleTimeout);
this.cycleTimeout = this.cyclePause = 0;
var $cont = $(this);
var $slides = opts.slideExpr ? $(opts.slideExpr, this) : $cont.children();
var els = $slides.get();
if (els.length < 2) {
log('terminating; too few slides: ' + els.length);
return;
}
var opts2 = buildOptions($cont, $slides, els, opts, o);
if (opts2 === false)
return;
var startTime = opts2.continuous ? 10 : getTimeout(els[opts2.currSlide], els[opts2.nextSlide], opts2, !opts2.rev);
// if it's an auto slideshow, kick it off
if (startTime) {
startTime += (opts2.delay || 0);
if (startTime < 10)
startTime = 10;
debug('first timeout: ' + startTime);
this.cycleTimeout = setTimeout(function(){go(els,opts2,0,(!opts2.rev && !opts.backwards))}, startTime);
}
});
'$ .fn.cycle'这是一个jQuery插件不是函数 – mgraph 2012-02-28 14:40:44
这是一个伟大的地方开始 - http://docs.jquery.com/Plugins/Authoring – jrummell 2012-02-28 14:41:23
@mgraph:'typeof $ .fn.cycle'会不同意。当然这是一个函数,但它被用来扩展jQuery,这使得它成为一个插件。 – 2012-02-28 14:41:25