2013-02-01 56 views
0

我在一个页面上有两个滑翔机幻灯片。 Slider#1(#slider)将显示Slider#2(#slider2)活动的选项卡,而不是来自Slider#1的活动幻灯片。我需要链接将其类更改为“活动”以获得正确的滑块。

这里就是它的发生:滑翔机幻灯片选项卡不能使用两个幻灯片 - 原型

this.current = $(element); 

$$('#slider div.controls a.active').invoke('removeClassName', 'active'); 
$$('#slider2 div.controls a.active').invoke('removeClassName', 'active'); 
$$('#slider a[href="#'+this.current.id+'"]').invoke('addClassName', 'active'); 

这里是我的HTML代码:

<a href="#section1">1</a> 
<a href="#section2">2</a> 
<a href="#section3">3</a> 

例小提琴 http://jsfiddle.net/hVGRy

+1

'$$'?这是一个错字吗? –

+1

你确定$是jQuery而不是另一个库吗? jQuery中没有addClassName。 –

+0

它使用原型的效果。我从这里得到这个代码http://code.google.com/p/missingmethod-projects/issues/detail?id=4#c12 –

回答

0

您使用的是错误的方式$符号。

在原型,$$$这么多彼此不同:

  • $等于document.getElementById,匹配元件返回,如果没有找到,则返回null;
  • $$等于document.querySelectorAll,返回包含匹配元素的数组,如果未找到,则返回[]

你的代码应该是这样的:

$$('#slider div.controls a.active').invoke('removeClassName', 'active'); 
$$('a[href=' + this.current.id + ']')[0].addClassName('active'); 

OK,原来只有一个幻灯片工作,这里有多个幻灯片黑客攻击:

// glider.js 
addObservers: function() { 
    var controls = this.wrapper.getElementsBySelector('.controls a'); 
    controls.invoke('observe', 'click', this.events.click); 
} 

moveTo: function(element, container, options){ 
    this.current = typeof element === 'string' ? this.wrapper.getElementsBySelector('#' + element)[0] : $(element) 

    this.wrapper.getElementsBySelector('.controls a.active').invoke('removeClassName', 'active') 
    this.wrapper.getElementsBySelector('a[href="#' + this.current.id + '"]').invoke('addClassName', 'active') 

    Position.prepare(); 
    var containerOffset = Position.cumulativeOffset(container), 
    elementOffset = Position.cumulativeOffset(this.current); 

    this.scrolling = new Effect.SmoothScroll(container, 
    {duration:options.duration, x:(elementOffset[0]-containerOffset[0]), y:(elementOffset[1]-containerOffset[1])}); 
    return false; 
} 

测试上我的机器。

+0

这适用于一个滑块。我需要它与两个滑块一起工作。 –

+0

@Daniel在jsfiddle或jsbin上发布带有两张幻灯片的示例代码,并澄清您的问题。 – Chris

+0

@Daniel如果你需要“点击幻灯片#1,幻灯片2改变幻灯片而不是幻灯片#1”,我认为你可以绑定幻灯片#1上的点击事件,如果它被触发,触发幻灯片#2的点击事件。 – Chris