Skip to content

Instantly share code, notes, and snippets.

@ashnur
Created October 3, 2012 20:41
Show Gist options
  • Select an option

  • Save ashnur/3829725 to your computer and use it in GitHub Desktop.

Select an option

Save ashnur/3829725 to your computer and use it in GitHub Desktop.
useless piece of code
void function(){
"use strict"
var bean = require('bean')
, KeySpline = require('./keyspline.js')
, splineFrom = new KeySpline(0.93,0.01,0.12,0.99)
, splineTo = new KeySpline(0.93,0.01,0.12,0.99)
, $ = function(id){ return document.getElementById.call(document, id) }
, $$ = function(selector, parent){ parent = parent || document; return parent.querySelectorAll.call(parent, selector) }
, lock = false
, slideshow , slides , steps, target
, sliderStep = 1
;
function createFader(elem, opacity){
return function(){elem.style.opacity = opacity}
}
function delClass(elem, classname){
elem.className = elem.className.replace( new RegExp('/(?:^|\s)'+classname+'(?!\S)/g') , '' )
}
function setClass(elem, classname){
elem.className = elem.className + ' '+classname
}
function switchClass(fromelem, toelem, classname){
fromelem.className = fromelem.className.replace( new RegExp('\\b'+classname+'\\b', 'g') , '' )
toelem.className = toelem.className + ' ' +classname
}
function crossfade(to){
var step
, from = $$('img.active', slideshow)[0]
;
if ( ! lock && from != to ) {
lock = true
from.style.opacity = 1
to.style.opacity = 0
to.style.display = 'block'
console.log(target)
switchClass($$('.active',$$('.control', slideshow )[0])[0], target, 'active')
for ( step = 1; step < 21; step++ ) {
setTimeout( createFader(from, 1 - splineFrom.get(step/20)) , 50*step )
setTimeout( createFader(to, splineTo.get(step/20)), 50*step )
if ( step == 20 ) {
setTimeout( function(){
from.style.display = 'none'
switchClass(from, to, 'active')
lock = false
}, 50*step)
}
}
}
}
function startSlider(){
sliderStep = sliderStep == 4 ? 1 : sliderStep + 1
target = $('control'+sliderStep)
crossfade($('sl'+sliderStep))
setTimeout(startSlider,7000)
}
bean.on(window, 'load', function(){
slideshow = $('slideshow')
slides = $('slides')
steps = $$('.steps img', slides )
setTimeout(startSlider,7000)
bean.on($$('#slides .control', slideshow)[0], 'click', '.switch', function(event){
var sl = parseInt((target = event.target).getAttribute('data-sl'))
;
event.stop()
crossfade($('sl'+sl))
})
})
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment