Skip to content

Instantly share code, notes, and snippets.

@samleb
Created September 6, 2013 10:05
Show Gist options
  • Select an option

  • Save samleb/6461919 to your computer and use it in GitHub Desktop.

Select an option

Save samleb/6461919 to your computer and use it in GitHub Desktop.
$$('.home_theater #carousel').each(function(element) {
var EFFECT_OPTIONS = {
duration: 0.75,
position: 'parallel',
transition: S2.FX.Transitions.easeFromTo
};
var slides = element.select('.slide'),
index = 0;
element.observe('click', handleClick);
function handleClick(e) {
var el = e.findElement('.arrow');
if (el) {
e.stop();
return moveToDirection(el.hasClassName('next') ? -1 : 1);
}
el = e.findElement('.toggle');
if (el) {
e.stop();
return toggleHotspots(el);
}
}
function moveToDirection(direction) {
var nextIndex = (slides.length + index + direction) % slides.length,
nextSlide = slides[nextIndex],
position = 1000 * direction;
slides[index].morph('left:' + position + 'px', EFFECT_OPTIONS);
nextSlide.style.display = 'block';
nextSlide.style.left = -position + 'px';
nextSlide.morph('left:0', EFFECT_OPTIONS);
index = nextIndex;
}
function toggleHotspots(button) {
var hotspots = button.up('.slide').down('.hotspots');
button.toggleClassName('on');
hotspots[button.hasClassName('on') ? 'appear' : 'fade']();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment