袖口:
function toggleArrows(e) {
e.stop();
// first discover clicked arow
var clickedArrow = e.findElement();
// second hide all arrows
$$('.toggle-arrow').invoke('hide');
// third find arrow that wasn't clicked
var arw = $$('.toggle-arrow').find(function(a) {
return a.identify() != clickedArrow.identify();
});
// fourth complete the toggle
if(arw)
arw.show();
}
像这样在文档加载事件中连接切换箭头功能
document.on('click','.toggle-arrow', toggleArrows.bindAsEventListener());
就是这样,但是如果您利用两个 css 类:箭头和箭头选择,您将获得更大的成功。然后,您可以使用这些类名轻松编写选择器来调用隐藏/显示“切换”,例如:
function toggleArrows(e) {
e.stop();
$$('.toggle-arrow').invoke('hide');
var arw = $$('.toggle-arrow').reject(function(r) {
r.hasClassName('arrow-selected'); });
$$('.arrow-selected').invoke('removeClassName', 'arrow-selected');
arw.show();
arw.addClassName('arrow-selected');
}